Ejemplo n.º 1
0
 public static tb_email_logs LogEmail(tb_email_logs data)
 {
     using (var context = new JobAppDBEntities())
     {
         data.log_entered_date = DateTime.UtcNow;
         var log = context.tb_email_logs.Add(data);
         context.SaveChanges();
         return(log);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates the email log.
 /// </summary>
 /// <param name="data">The data.</param>
 public static void UpdateEmailLog(tb_email_logs data)
 {
     using (var context = new JobAppDBEntities())
     {
         var log = context.tb_email_logs.Find(data.email_log_id);
         if (log == null)
         {
             return;
         }
         log.error   = data.error;
         log.content = data.content;
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        private static void StartMailer(string email, string ccAddress, string subject, string content, string txnId, int mailType, string username, long user_id, int type)
        {
            mailType = 1;
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (s, e) =>
            {
                tb_email_logs log = new tb_email_logs();
                try
                {
                    log = MailerContext.LogEmail(new tb_email_logs()
                    {
                        cc               = ccAddress ?? "",
                        content          = HttpUtility.UrlDecode(content ?? ""),
                        error            = "",
                        has_attachement  = false,
                        subject          = subject ?? "",
                        to               = email ?? "",
                        log_entered_date = DateTime.UtcNow,
                        user_identifier  = user_id.ToString()
                    });
                }
                catch (Exception)
                {
                }

                try
                {
                    var smtp = SmtpProvider.GetSmtpSettingFor(mailType);
                    // TODO : Fetch the details from the Web-Admin
                    MailMessage message = new MailMessage();
                    if (email.Contains(";"))
                    {
                        message.From = new MailAddress(smtp.FromAddress);
                        foreach (var item in email.Split(';'))
                        {
                            if (string.IsNullOrEmpty(item))
                            {
                                continue;
                            }
                            message.To.Add(new MailAddress(item));
                        }
                        message.Subject = subject;
                        message.Body    = HttpUtility.UrlDecode(content);
                    }
                    else if (email.Contains(","))
                    {
                        message.From = new MailAddress(smtp.FromAddress);
                        foreach (var item in email.Split(','))
                        {
                            if (string.IsNullOrEmpty(item))
                            {
                                continue;
                            }
                            message.To.Add(new MailAddress(item));
                        }
                        message.Subject = subject;
                        message.Body    = HttpUtility.UrlDecode(content);
                    }
                    else
                    {
                        message = new MailMessage(smtp.FromAddress, email, subject, HttpUtility.UrlDecode(content));
                    }

                    message.IsBodyHtml = true;
                    //message.Attachments.Add(attachment);
                    SmtpClient cnt = new SmtpClient(smtp.Address, Convert.ToInt16(smtp.Port));
                    cnt.Timeout = 2000000;
                    cnt.UseDefaultCredentials = false;
                    cnt.EnableSsl             = true;
                    //cnt.Host = smtp.Address;

                    if (!smtp.UseAnonymous)
                    {
                        cnt.Credentials = new System.Net.NetworkCredential(smtp.UserName, smtp.Password);
                    }
                    cnt.Send(message);
                }
                catch (Exception ex)
                {
                    try
                    {
                        e.Result  = email;
                        log.error = ex.ToString();
                        MailerContext.UpdateEmailLog(log);
                    }
                    catch (Exception)
                    {
                    }
                    //throw ex;
                }
            };
            worker.RunWorkerAsync();
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
        }