Ejemplo n.º 1
0
        public bool Send(string toaddress, string subject, string body, string ToName)
        {
            var fromAddress = new MailAddress(this.fromemail, fromName);
            var toAddress = new MailAddress(toaddress, ToName);
            string fromPassword = this.frompwd;
            int iPort;
            int.TryParse(this.port, out iPort);
            var smtp = new SmtpClient
            {
                Host = this.smtpHost,
                Port = iPort,
                EnableSsl = enableSSL,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
                Timeout = 20000
            };

            bool result = true;
            BestTable tbl = new BestTable();
            OleDbCommand myCmd = tbl.dbCmd;
            myCmd.CommandText = "insert into BestLogs (message) values (?)";
            OleDbParameter p1 = new OleDbParameter("msg", OleDbType.VarChar, 9999999);

            try
            {
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    IsBodyHtml = true,
                    Subject = subject,
                    Body = body
                })
                {
                    p1.Value = "From:" + fromAddress.DisplayName + " To:" + toaddress + " Subject:" + subject + " Body:" + body;
                    myCmd.Parameters.Add(p1);
                    myCmd.ExecuteNonQuery();
                    smtp.Send(message);
                }
            }
            catch (Exception ex)
            {
                result = false;
                lastError = ex.Message;
                myCmd.Parameters[0].Value = ex.ToString();
                myCmd.ExecuteNonQuery();
            }

            return result;
        }
Ejemplo n.º 2
0
        private string getExportData(string exptype, string fields)
        {
            StringBuilder sb = new StringBuilder();
            string tsql = "";
            if (exptype.Equals("Payments"))
            {
                tsql = "select " + fields + " From (" +  UtilExporter.PaymentSQL() + ") t1";
            }
            else if (exptype.Equals("Students"))
            {
                tsql = "select " + fields + " From (" + UtilExporter.StudentSQL() + ") t1";
            }
            else if (exptype.Equals("Tutors"))
            {
                tsql = "select " + fields + " From (" + UtilExporter.TutorSQL() + ") t1";
            }
            else if (exptype.Equals("Change Audit"))
            {
                tsql = "select " + fields + " From (" + UtilExporter.ChangeAuditSQL() + ") t1";
            }
            else if (exptype.Equals("Schedules"))
            {
                tsql = "select " + fields + " From (" + UtilExporter.ScheduleSQL() + ") t1";
            }

            if (tsql.Length > 0)
            {
                BestTable tbl = new BestTable();
                OleDbCommand myCmd = tbl.dbCmd;
                myCmd.CommandText = "insert into BestLogs (message) values (?)";
                OleDbParameter p1 = new OleDbParameter("msg", OleDbType.VarChar, 9999999);
                p1.Value = tsql;
                myCmd.Parameters.Add(p1);
                myCmd.ExecuteNonQuery();

                myCmd.Parameters.Clear();
                myCmd.CommandText = tsql;
                OleDbDataReader expReader = myCmd.ExecuteReader();
                string aline = "";
                while (expReader.Read())
                {
                    aline = "";
                    for (int i = 0; i < expReader.FieldCount; i++)
                    {
                        object val = expReader.GetValue(i);
                        aline += "\"" + (val.ToString()) + "\",";
                    }
                    sb.AppendLine(aline);
                }
                expReader.Close();
            }
            return sb.ToString();
        }
Ejemplo n.º 3
0
        private string ReplaceParams(BestTable bsrow, string emailbody)
        {
            string result = emailbody;
            string name = bsrow.CurrentRow.Fields["firstName"].fieldValue + " " + bsrow.CurrentRow.Fields["lastName"].fieldValue;
            //{tutor}
            //{student}
            result = result.Replace("{tutor}", name);
            result = result.Replace("{student}", name);
            string fromdate = Request.Form["fromdate"] ?? "";
            string todate = Request.Form["todate"] ?? "";
            if (!string.IsNullOrEmpty(fromdate))
            {
                //{WeekStartDate}
                result = result.Replace("{WeekStartDate}", fromdate);
            }
            if (!string.IsNullOrEmpty(todate))
            {
                //{WeekEndDate}
                result = result.Replace("{WeekEndDate}", todate);
            }
            //{WeeklySchedule}
            if (emailbody.IndexOf("{WeeklySchedule}") > 0)
            {
                string tsql = "select Date, [Sunday], [Monday], [Tuesday], [Wednesday], [Thursday], [Friday], [Saturday], stud1name, stud2name, stud3name, stud4name, stud5name from VBestSchedules where ";
                string guidstr = bsrow.CurrentRow.Fields["guidfield"].fieldValue;
                if (bsrow is BestStudents)
                {
                    tsql += "(stuGuid1='" + guidstr + "' or stuGuid2='" + guidstr + "' or stuGuid3='" + guidstr + "' or stuGuid4='" + guidstr + "' or stuGuid5='" + guidstr + "')";
                }
                else if (bsrow is BestTutors)
                {
                    tsql += " tutGuid='" + guidstr + "'";
                }
                tsql += @" and convert(datetime,date) between '" + fromdate + @"' and '" + todate + @"' order by convert(datetime, date), convert(numeric, schfrom)";

                StringBuilder sbSchd = new StringBuilder();
                BestDatabase db = new BestDatabase();
                OleDbCommand myCmd = db.dbCmd;
                myCmd.CommandText = tsql;
                OleDbDataReader tblReader = myCmd.ExecuteReader(CommandBehavior.KeyInfo);
                //Retrieve column schema into a DataTable.
                DataTable schemaTable = tblReader.GetSchemaTable();

                sbSchd.Append("<table cellpadding=\"0\" style=\"padding:1px;font-family:Tahoma;font-size:12px;border:1px solid #999;background-color:#A11117\"><tr>");
                //For each field in the table...
                int fieldCnt = 0;
                foreach (DataRow myField in schemaTable.Rows)
                {
                    fieldCnt++; if (fieldCnt > 8) break;
                    sbSchd.Append("<th style=\"color:#000;background-color:#E9BA15;padding:2px;\">" + myField[0] + "</th>");
                }
                sbSchd.Append("</tr>");

                int cnt = 0;
                while (tblReader.Read())
                {
                    if (bsrow is BestStudents)
                    {
                        name = "";
                    }
                    else
                    {
                        name = " " + tblReader[8].ToString();
                        name += !string.IsNullOrEmpty(tblReader[9].ToString()) ? ", " + tblReader[9].ToString() : "";
                        name += !string.IsNullOrEmpty(tblReader[10].ToString()) ? ", " + tblReader[10].ToString() : "";
                        name += !string.IsNullOrEmpty(tblReader[11].ToString()) ? ", " + tblReader[11].ToString() : "";
                        name += !string.IsNullOrEmpty(tblReader[12].ToString()) ? ", " + tblReader[12].ToString() : "";
                    }
                    string trclass = (cnt % 2 == 0) ? "" : "trordd";
                    sbSchd.Append("<tr style=\"font-family:Tahoma;color:#FFF;font-size:12px;\"><td>" + (tblReader[0].ToString()) + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[1].ToString()) + (!string.IsNullOrEmpty(tblReader[1].ToString()) ? name : "") + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[2].ToString()) + (!string.IsNullOrEmpty(tblReader[2].ToString()) ? name : "") + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[3].ToString()) + (!string.IsNullOrEmpty(tblReader[3].ToString()) ? name : "") + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[4].ToString()) + (!string.IsNullOrEmpty(tblReader[4].ToString()) ? name : "") + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[5].ToString()) + (!string.IsNullOrEmpty(tblReader[5].ToString()) ? name : "") + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[6].ToString()) + (!string.IsNullOrEmpty(tblReader[6].ToString()) ? name : "") + "</td>");
                    sbSchd.Append("<td>" + Utils.ToTimeFormat(tblReader[7].ToString()) + (!string.IsNullOrEmpty(tblReader[7].ToString()) ? name : "") + "</td></tr>");
                    cnt++;
                }
                tblReader.Close();

                sbSchd.Append("</table>");
                result = result.Replace("{WeeklySchedule}", sbSchd.ToString());
            }
            result = result.Replace("\n\r", "<br />");

            return result;
        }
Ejemplo n.º 4
0
        public bool SendMultiple(NameValueCollection ToAddrs, string subject, string body)
        {
            bool result = true;
            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress(this.fromemail, this.fromName);
            foreach(string key in ToAddrs.AllKeys)
            {
                mailMsg.To.Add( new MailAddress(key, ToAddrs[key]));
            }
            mailMsg.Subject = subject;
            mailMsg.Body = body;

            int iPort;
            int.TryParse(this.port, out iPort);
            var fromAddress = new MailAddress(this.fromemail, fromName);
            string fromPassword = this.frompwd;

            BestTable tbl = new BestTable();

            var smtp = new SmtpClient
            {
                Host = this.smtpHost,
                Port = iPort,
                EnableSsl = enableSSL,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
                Timeout = 20000
            };

            OleDbCommand myCmd = tbl.dbCmd;
            myCmd.CommandText = "insert into BestLogs (message) values (?)";
            OleDbParameter p1 = new OleDbParameter("msg", OleDbType.VarChar, 9999999);
            try
            {
                p1.Value = "From:" + fromAddress.DisplayName + " To:" + mailMsg.To.ToString() + " Subject:" + subject + " Body:" + body;
                myCmd.Parameters.Add(p1);
                myCmd.ExecuteNonQuery();
                smtp.Send(mailMsg);
            }
            catch (Exception ex)
            {
                result = false;
                lastError = ex.Message;
                myCmd.Parameters[0].Value = ex.ToString();
                myCmd.ExecuteNonQuery();
            }

            return result;
        }