public void TestEmail() { EmailParameters mailParams = new EmailParameters(); mailParams.Server = "secure.emailsrvr.com"; mailParams.UserName = "******"; mailParams.Password = "******"; mailParams.Port = 465; mailParams.To = "*****@*****.**"; mailParams.From = "*****@*****.**"; mailParams.Body = "Test message from UnitTest"; mailParams.Subject = "Unit Testing mail sending"; EmailHelper.Send(mailParams); }
private static SmtpClient GetClient(EmailParameters mailParams) { SmtpClient smtp = new SmtpClient(mailParams.Server, mailParams.Port); //smtp.UseDefaultCredentials = false; smtp.EnableSsl = true; smtp.Timeout = 30 * 1000; //smtp.DeliveryMethod = SmtpDeliveryMethod.Network; NetworkCredential credential = new NetworkCredential(mailParams.UserName, mailParams.Password); smtp.Credentials = credential; //smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //smtp.DeliveryFormat = SmtpDeliveryFormat.SevenBit; //smtp. return smtp; }
public static void Send(EmailParameters mailParams) { { SmtpClient smtp = GetClient(mailParams); MailMessage message = new MailMessage(mailParams.From, mailParams.To); message.Subject = mailParams.Subject; message.Body = mailParams.Body; message.IsBodyHtml = true; try { smtp.Send(message); } catch(SmtpException ex) { log.Error("Error sending email!", ex); } smtp.Dispose(); } }