private void butnSendMail_Click(object sender, System.EventArgs e) { butnSendMail.Enabled = false; try { Indy.Sockets.Message LMsg = new Indy.Sockets.Message(); LMsg.From.Text = textFrom.Text.Trim(); LMsg.Recipients.Add().Text = textTo.Text.Trim(); LMsg.Subject = textSubject.Text.Trim(); LMsg.Body.Text = textMsg.Text; // Attachment example // new AttachmentFile(LMsg.MessageParts, @"c:\temp\Hydroponics.txt"); SMTP LSMTP = new SMTP(); LSMTP.OnStatus += new Indy.Sockets.TIdStatusEvent(SMTPStatus); LSMTP.Host = textSMTPServer.Text.Trim(); LSMTP.Connect(); try { LSMTP.Send(LMsg); Status("Completed"); } finally { LSMTP.Disconnect(); } } finally { butnSendMail.Enabled = true; } }
public void ProbarCorreo(string remitente, string servidorSmtp, string contenido, string asunto, string destinatario) { EmailMessage email = new EmailMessage(destinatario, remitente, asunto, contenido, BodyPartFormat.Plain); SMTP smtpClient = new SMTP(servidorSmtp); smtpClient.Send(email); }
public static void SendThread() { //create SMTP object SMTP objSMTP = new SMTP(); objSMTP.SMTPServers.Add("smtp.socketlabs.com", 25, 60, SMTPAuthMode.AuthLogin, "your_smtp_user", "your_smtp_password"); /* * this sample just sends one message per thread/connection but in the real world you should send about * 50-100 messages per connection. You will have to add your database retrieval and loop management here * * i.e. grab 50 records from db, connect, loop through and send all 50 and then disconnect * repeat as long as there are more records to process in database */ //establish connection and keep it open for all messages we send objSMTP.Connect(); EmailMessage objMessage = new EmailMessage(); objMessage.From = new Address("*****@*****.**", "Sender Name"); objMessage.Recipients.Add("*****@*****.**", "Recipient Name", RecipientType.To); objMessage.Subject = "Subject..."; objMessage.BodyParts.Add("Hi ##FIRSTNAME##, Thank you for your interest in ##PRODUCT##.", BodyPartFormat.Plain, BodyPartEncoding.QuotedPrintable); Dictionary<string, string> tokens = new Dictionary<string, string>(); tokens["##FIRSTNAME##"] = "John"; tokens["##PRODUCT##"] = "SocketLabs Email On-Demand"; objMessage.BodyParts[0].Body = BulkReplace(objMessage.BodyParts[0].Body, tokens); objSMTP.Send(objMessage); //close connection after all messages have been sent objSMTP.Disconnect(); Interlocked.Decrement(ref threadsOpen); }
public void SendNotification(string name, string phone, string email) { var subject = "RBT Course Payment"; var message = $@"Name: {name} Phone: {phone} Email: {email}"; SMTP.Send(SMTPAccount, subject, message, Recipient); }
public void SendMessage(string From, string To, string MessageText, string MessageSubject, Window MainWindow) { Message = new MailMessage(From, To, MessageSubject, MessageText); try { SMTP.Send(Message); StaticVariables.GetNewMessageWindow(MainWindow, "Success", "Your email has been sent!", Brushes.GreenYellow).ShowDialog(); } catch (Exception E) { WindowCollection WC = MainWindow.OwnedWindows; StaticVariables.GetNewMessageWindow(MainWindow, "Sending Error", E.Message, Brushes.DarkRed).ShowDialog(); } }
private void EnviarCorreoEnNuevoThread(string servidorSmtp, EmailMessage email, Action callback) { // Obtenemos a quienes se envio el correo string recipients = string.Join(", ", ObtenerRecipientes(email)); try { SMTP smtpClient = new SMTP(servidorSmtp); // Enviamos el correo smtpClient.Send(email); log.InfoFormat("Email enviado a: {0}", recipients); log.InfoFormat("Total de email enviados: {0}", email.Recipients.Count); try { if (callback != null) { callback(); } } catch (Exception e) { log.ErrorFormat("Ocurrio un error al momento de llamar la funcion 'callback' luego en enviar correctamente el email a: {0}", recipients); log.Error(e); } } catch (Exception e) { log.ErrorFormat("Ocurrio un error al momento de estar mandando un email a: {0}", recipients); log.Error(e); } finally { while (email.BodyParts.MoveNext()) { if (email.BodyParts.Current is BodyPart) { log.DebugFormat("Contenido del Email: {0}", ((BodyPart)email.BodyParts.Current).Body); } } } }
public static void SendThread() { //create SMTP object SMTP objSMTP = new SMTP(); objSMTP.SMTPServers.Add("smtp.socketlabs.com", 25, 60, SMTPAuthMode.AuthLogin, "your_smtp_user", "your_smtp_password"); /* * this sample just sends one message per thread/connection but in the real world you should send about * 50-100 messages per connection. You will have to add your database retrieval and loop management here * * i.e. grab 50 records from db, connect, loop through and send all 50 and then disconnect * repeat as long as there are more records to process in database */ //establish connection and keep it open for all messages we send objSMTP.Connect(); EmailMessage objMessage = new EmailMessage(); objMessage.From = new Address("*****@*****.**", "Sender Name"); objMessage.Recipients.Add("*****@*****.**", "Recipient Name", RecipientType.To); objMessage.Subject = "Subject..."; objMessage.BodyParts.Add("Hi ##FIRSTNAME##, Thank you for your interest in ##PRODUCT##.", BodyPartFormat.Plain, BodyPartEncoding.QuotedPrintable); Dictionary <string, string> tokens = new Dictionary <string, string>(); tokens["##FIRSTNAME##"] = "John"; tokens["##PRODUCT##"] = "SocketLabs Email On-Demand"; objMessage.BodyParts[0].Body = BulkReplace(objMessage.BodyParts[0].Body, tokens); objSMTP.Send(objMessage); //close connection after all messages have been sent objSMTP.Disconnect(); Interlocked.Decrement(ref threadsOpen); }
public void SendShouldSendEmailWhenReplyToEmailIsNotDefined() { // Arrange var smtp = new SMTP(); var rockEmailMessage = new RockEmailMessage(); rockEmailMessage.ReplyToEmail = null; rockEmailMessage.AddRecipient(new RockEmailMessageRecipient(new Person { Email = "*****@*****.**", FirstName = "Test", LastName = "User" }, new Dictionary <string, object>())); // Act smtp.Send((RockMessage)rockEmailMessage, 0, new Dictionary <string, string>(), out List <string> errorMessages); // Assert Assert.That.AreEqual(0, errorMessages.Count, errorMessages.JoinStrings(", ")); }
public void Can_SendMail() { Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.SMTPHost), "SMTP Host is not set"); Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.Username), "Username is not set"); Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.Password), "Password is not set"); Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.To), "MailOptions.To email address is not set"); Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.From), "MailOptions.From email address is not set"); Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.Body), "Email body is not set"); Debug.Assert(MailOptions.SMTPPort != 0, "SMTP Port is not set"); // Generate a random subject header to cross check with the emails received. MailOptions.Subject = RngStringProvider.GenerateString(12); Debug.Assert(!string.IsNullOrWhiteSpace(MailOptions.Subject), "Email subject is not set"); SMTP.Send(MailOptions); Console.WriteLine("Email sent \n\n" + "Checking if email is received for a duration of 30 seconds...\n"); int seconds = 0; while (seconds < 30) { Thread.Sleep(1000); string html = Http.Get("http://www.dispostable.com/inbox/netutilities/?last=0"); if (html.Contains(MailOptions.Subject)) { break; } Console.WriteLine("Seconds: {0}", seconds++); Debug.Assert(seconds < 30, "Mail has not been received by the client, check your mail options."); } Console.WriteLine("\nReceived mail!"); }
} // Tesde simples de conexão à internet. public static bool Send(string cliente, string dest, string senha, string titulo, string msg) //recebe as informações para o email { int index = cliente.LastIndexOf('@'); // variavel para pegar contar todos os valores antes do @ SmtpClient SMTP = new SmtpClient(); // envio SMTP // a diferença de cada provedor de emial está no seu host e a porta de comunicação basicamente. //email de envio gmail.com if (cliente.Substring(index) == "@gmail.com" || cliente.Substring(index) == "@gmail.com.br") //se for retirado dos os carcteres entes do @, e o que sobrar for igual à "@gmail.com" { //configuração do SMTP. porta, host, timeout, etc SMTP = new SmtpClient("smtp.gmail.com", 587); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = true; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } //email de envio Hotmail.com else if (cliente.Substring(index) == "@hotmail.com" || cliente.Substring(index) == "@hotmail.com.br") { SMTP = new SmtpClient("smtp-mail.outlook.com", 587); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = true; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } else if (cliente.Substring(index) == "@yahoo.com" || cliente.Substring(index) == "@yahoo.com.br") { SMTP = new SmtpClient("smtp.mail.yahoo.com", 465); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = true; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } else if (cliente.Substring(index) == "@mafrainformatica.com" || cliente.Substring(index) == "@mafrainformatica.com.br") { SMTP = new SmtpClient("mail.mafrainformatica.com.br", 587); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = false; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } MailMessage mail = new MailMessage(cliente, dest, titulo, msg); mail.BodyEncoding = UTF8Encoding.UTF8; Console.WriteLine("\nEnviando email...."); try { SMTP.Send(mail); return(true); } catch (Exception ex) { Console.Write(ex.Message); return(false); } }
} // Tesde simples de conexão à internet. public static void Send(string cliente, string dest, string senha, string titulo, string msg) //recebe as informações para o email { int index = cliente.LastIndexOf('@'); // variavel para pegar contar todos os valores antes do @ SmtpClient SMTP = new SmtpClient(); // envio SMTP // a diferença de cada provedor de emial está no seu host e a porta de comunicação basicamente. //email de envio gmail.com if (cliente.Substring(index) == "@gmail.com" || cliente.Substring(index) == "@gmail.com.br") //se for retirado dos os carcteres entes do @, e o que sobrar for igual à "@gmail.com" { //configuração do SMTP. porta, host, timeout, etc SMTP = new SmtpClient("smtp.gmail.com", 587); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = true; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } //email de envio Hotmail.com else if (cliente.Substring(index) == "@hotmail.com" || cliente.Substring(index) == "@hotmail.com.br") { SMTP = new SmtpClient("smtp-mail.outlook.com", 587); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = true; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } else if (cliente.Substring(index) == "@yahoo.com" || cliente.Substring(index) == "@yahoo.com.br") { SMTP = new SmtpClient("smtp.mail.yahoo.com", 465); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = true; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } else if (cliente.Substring(index) == "@mafrainformatica.com" || cliente.Substring(index) == "@mafrainformatica.com.br") { SMTP = new SmtpClient("mail.mafrainformatica.com.br", 587); // cria protocolo SMTP, informando o host(no caso O Gmail e a porta de envio dele. tais informações são retiradas do provedor de email SMTP.EnableSsl = false; //Conexão encriptografada. SMTP.Timeout = 10000; //tempo de tentativa de envio. SMTP.DeliveryMethod = SmtpDeliveryMethod.Network; //qual será o método de entrega do email? Internet SMTP.UseDefaultCredentials = false; // SMTP.Credentials = new NetworkCredential(cliente, senha); } try { //Corpo do email MailMessage mail = new MailMessage(cliente, dest); mail.Subject = titulo; mail.IsBodyHtml = true; mail.Body = msg; //Setting img string img; if (File.Exists("DataFooter")) { using (StreamReader filefooter = new StreamReader("DataFooter")) { string[] splt = Encription.Decription(filefooter.ReadLine()).Split('\\'); img = splt.LastOrDefault(); filefooter.Close(); } if (!String.IsNullOrEmpty(img)) { LinkedResource footerImg = new LinkedResource(img, "image/jpeg"); footerImg.ContentId = "companyLogo"; AlternateView foot = AlternateView.CreateAlternateViewFromString(msg + "<p> <img src=cid:companyLogo /> </p>", null, "text/html"); foot.LinkedResources.Add(footerImg); mail.AlternateViews.Add(foot); } } //Definindo anexos Attachment file = new Attachment(Program.PDFNomefile, MediaTypeNames.Application.Pdf); Attachment file2 = new Attachment(Program.PDFQuantFile, MediaTypeNames.Application.Pdf); mail.Attachments.Add(file); mail.Attachments.Add(file2); mail.BodyEncoding = UTF8Encoding.UTF8; Console.WriteLine("\nEnviando email...."); SMTP.Send(mail); } catch (Exception ex) { Console.Write(ex.Message); return; } DateTime TempoRecebe = DateTime.Now; Console.Write("Email enviado com sucesso. " + TempoRecebe); }
static void Main(string[] args) { Quiksoft.EasyMail.SMTP.License.Key = "Scott Griswold (Single Developer)/8008767F195514552F8DE5C145E3A7"; firstDate = DateTime.Now.ToShortDateString(); secondDate = DateTime.Now.AddDays(1).ToShortDateString(); Walden.Medical.Library.ChangeWindowState.SetConsoleWindowVisibility(false, Console.Title); Database.WaldenReminderConnection = System.Configuration .ConfigurationManager.AppSettings["walden"]; try { using (SqlConnection cn = new SqlConnection(Database.WaldenReminderConnection)) { cn.Open(); using (SqlCommand cm = cn.CreateCommand()) { cm.CommandText = " SELECT count(SendID)" + " FROM [dbo].[FaxesSendServer]" + " where status ='Completed'" + " and createtime between '" + firstDate + "' and '" + secondDate + "'"; SqlDataReader dr = cm.ExecuteReader(); dr.Read(); numberOfSuccessfulfaxes = dr.GetInt32(0); } } } catch(Exception er) { string s1 = er.Message; } try { using (SqlConnection cn = new SqlConnection(Database.WaldenReminderConnection)) { cn.Open(); using (SqlCommand cm = cn.CreateCommand()) { cm.CommandText = " SELECT count(SendID)" + " FROM [dbo].[FaxesSendServer]" + " where status NOT IN ('Completed')" + " and createtime between '" + firstDate + "' and '" + secondDate + "'"; SqlDataReader dr = cm.ExecuteReader(); dr.Read(); numberOfUnSuccessfulfaxes = dr.GetInt32(0); _emailTo = System.Configuration .ConfigurationManager.AppSettings["EmailTo"]; _smtpServer = System.Configuration .ConfigurationManager.AppSettings["SMTPServer"]; //Create the EmailMessage object EmailMessage _messageObject = new EmailMessage(); _messageObject.Subject = "Reminder Call Report"; //Add a normal recipient _messageObject.Recipients.Add(_emailTo); Debug.WriteLine(_emailTo); //Specify the sender _messageObject.From.Email = _emailTo; //_messageObject.From.Email = "*****@*****.**"; _messageObject.From.Name = "Daily Fax Activity"; string messagebody = "Fax Activity for " + firstDate + Environment.NewLine + " Successful faxes: " + numberOfSuccessfulfaxes.ToString() + Environment.NewLine + " Number of Unsuccessful faxes: " + numberOfUnSuccessfulfaxes.ToString(); //Set message body _messageObject.BodyParts.Add(messagebody); //Add attachment //_messageObject.Attachments.Add(_ApplicationPath + "\\Report.pdf"); //Specify the mail server and enable authentication _server.Name = _smtpServer; Debug.WriteLine(_smtpServer); // _server.Account = _smtpUID; // _server.Password = _smtpPWD; _server.AuthMode = SMTPAuthMode.None; SMTP _smtpObject = new SMTP(); try { //Add mail server _smtpObject.SMTPServers.Add(_server); //Send the message _smtpObject.Send(_messageObject); } catch (FileIOException FileIOExcep) { Console.WriteLine("File IO error: " + FileIOExcep.Message); return; } catch (SMTPAuthenticationException SMTPAuthExcep) { Console.WriteLine("SMTP Authentication error: " + SMTPAuthExcep.Message); return; } catch (SMTPConnectionException SMTPConnectExcep) { Console.WriteLine("Connection error: " + SMTPConnectExcep.Message); return; } catch (SMTPProtocolException SMTPProtocolExcep) { Console.WriteLine("SMTP protocol error: " + SMTPProtocolExcep.Message); return; } Console.WriteLine("Message sent."); } } } catch (Exception er) { string s1 = er.Message; } }
private void SendEmail(Email email, SMTP smtp) { Logs.WriteLine(); Logs.WriteHeader("Processing Email"); Logs.WriteEventFormat("EmailID: {0}, EmailPostID: {1}", email.EmailID.ToString(), email.EmailPostID.ToString()); Organization organization = Organizations.GetOrganization(LoginUser, email.OrganizationID); if (!organization.IsActive) { email.IsSuccess = true; email.IsWaiting = false; email.Body = ""; email.DateSent = DateTime.UtcNow; email.LastFailedReason = "Organization is inactive, not sent"; email.Collection.Save(); return; } // if trial org if (organization.UserSeats == 100 && organization.DateCreated.AddDays(30) > DateTime.UtcNow) { if (Emails.IsTrialEmailOverLimit(LoginUser, organization.OrganizationID)) { if (!(email.Subject.ToUpper().Contains("PASSWORD") || email.Subject.ToUpper().Contains("WELCOME"))) { email.IsSuccess = true; email.IsWaiting = false; email.Body = ""; email.DateSent = DateTime.UtcNow; email.LastFailedReason = "Organization has gone over the trial email limits."; email.Collection.Save(); return; } } } try { email.Attempts = email.Attempts + 1; email.Collection.Save(); Logs.WriteEvent("Attempt: " + email.Attempts.ToString()); Logs.WriteEventFormat("Size: {0}, Attachments: {1}", email.Size.ToString(), email.Attachments); MailMessage message = email.GetMailMessage(); if (_isDebug == true) { string debugWhiteList = Settings.ReadString("Debug Email White List", ""); string debugDomains = Settings.ReadString("Debug Email Domains", ""); string debugAddresses = Settings.ReadString("Debug Email Address", ""); if (!string.IsNullOrWhiteSpace(debugWhiteList)) { Logs.WriteEvent("DEBUG Whitelist: " + debugWhiteList); string[] addresses = debugWhiteList.Replace(';', ',').Split(','); List <MailAddress> mailAddresses = new List <MailAddress>(); foreach (MailAddress mailAddress in message.To) { foreach (string address in addresses) { if (mailAddress.Address.ToLower().IndexOf(address.ToLower()) > -1) { mailAddresses.Add(mailAddress); } } } message.To.Clear(); foreach (MailAddress mailAddress in mailAddresses) { message.To.Add(mailAddress); } } else if (!string.IsNullOrWhiteSpace(debugDomains)) { Logs.WriteEvent("DEBUG Domains: " + debugDomains); string[] domains = debugDomains.Replace(';', ',').Split(','); List <MailAddress> mailAddresses = new List <MailAddress>(); foreach (MailAddress mailAddress in message.To) { foreach (string domain in domains) { if (mailAddress.Address.ToLower().IndexOf(domain.ToLower()) > -1) { mailAddresses.Add(mailAddress); } } } message.To.Clear(); foreach (MailAddress mailAddress in mailAddresses) { message.To.Add(mailAddress); } } else if (!string.IsNullOrWhiteSpace(debugAddresses)) { Logs.WriteEvent("DEBUG Addresses: " + debugAddresses); message.To.Clear(); message.To.Add(debugAddresses.Replace(';', ',')); } else { Logs.WriteEvent("NO DEBUG FILTERS SET"); return; } if (message.To.Count < 1) { Logs.WriteEvent("No Debug Address specified."); email.IsSuccess = true; email.IsWaiting = false; email.Body = ""; email.DateSent = DateTime.UtcNow; email.LastFailedReason = "No Debug Address specified."; email.Collection.Save(); return; } message.Subject = string.Format("[{0}] {1}", Settings.ReadString("Debug Email Subject", "TEST MODE"), message.Subject); } Logs.WriteEvent("Sending email"); EmailMessage msg = new EmailMessage(); msg.CharsetEncoding = System.Text.Encoding.UTF8; foreach (var recipient in message.To) { msg.Recipients.Add(recipient.Address, recipient.DisplayName); } msg.From.Name = message.From.DisplayName; msg.From.Email = message.From.Address; msg.ReplyTo = message.From.Address; msg.Subject = message.Subject; msg.CustomHeaders.Add("X-xsMessageId", email.OrganizationID.ToString()); msg.CustomHeaders.Add("X-xsMailingId", email.EmailID.ToString()); msg.BodyParts.Add(new Quiksoft.EasyMail.SMTP.BodyPart(message.Body, message.IsBodyHtml ? BodyPartFormat.HTML : BodyPartFormat.Plain)); if (email.Size < 25000) { string[] attachments = email.GetAttachments(); foreach (var attachment in attachments) { if (File.Exists(attachment)) { msg.Attachments.Add(attachment); } else { Logs.WriteEvent("File unavailable :" + attachment); } } } try { smtp.Send(msg); } catch (Quiksoft.EasyMail.SMTP.SMTPProtocolException smtpEx) { Logs.WriteEvent(smtpEx.ToString()); if (smtpEx.Message.IndexOf("5.3.4") > -1) { msg.Attachments.Clear(); smtp.Send(msg); } } Logs.WriteEvent("Email sent"); email.IsSuccess = true; email.IsWaiting = false; email.Body = ""; email.DateSent = DateTime.UtcNow; email.Collection.Save(); UpdateHealth(); } catch (Exception ex) { if (ex is Quiksoft.EasyMail.SSL.SSLConnectionException) { throw ex; } else { Logs.WriteEvent("Error sending email"); Logs.WriteException(ex); ExceptionLogs.LogException(LoginUser, ex, _threadPosition.ToString() + " - Email Sender", email.Row); StringBuilder builder = new StringBuilder(); builder.AppendLine("Log File: " + _threadPosition.ToString()); builder.AppendLine(ex.Message); builder.AppendLine(ex.StackTrace); email.NextAttempt = DateTime.UtcNow.AddMinutes(_nextAttempts[email.Attempts - 1] * email.Attempts); email.LastFailedReason = builder.ToString(); email.IsSuccess = false; email.IsWaiting = (email.Attempts < _nextAttempts.Length); email.LockProcessID = null; email.Collection.Save(); } } }