public void DispatchEmailMessage(EmailMessage email) { try { if (string.IsNullOrEmpty(email.ToEmailAddress)) { email.ToEmailAddress = ConfigItems.SystemEmailAddress; email.ToName = "AirtimeBilling No Address"; } using (var outgoing = email.GetMessage()) { var mailClient = new SmtpClient(); mailClient.Send(outgoing); var emailLogMsg = string.Format("Sent email SMTP Server: {0}, Mail From: {1}, Mail To: {2}", mailClient.Host, outgoing.From.Address, outgoing.To[0].Address); LoggingUtility.LogDebug("DispatchEmailMessage", "EmailService", emailLogMsg); } } catch (Exception ex) { // Do not send Error email. LoggingUtility.LogException(ex, false); } }
public static void SendEmailWithAttachments(string toAddress, string toName, string subject, IEmailFormat message, bool highPriority, IList<string> attachmentFilenames) { var msg = new EmailMessage { ToEmailAddress = toAddress, ToName = toName, Subject = subject, Body = message.GetHtml(), IsBodyHtml = true, IsHighPriority = highPriority, FilesToAttach = attachmentFilenames ?? new List<string>() }; EmailMessageAgent agent = null; try { agent = new EmailMessageAgent(); agent.DispatchEmailMessage(msg); } finally { if (agent != null) agent.Close(); } }
public static void SendEmail(string toAddress, string toName, string subject, IEmailFormat message, bool highPriority) { var msg = new EmailMessage { ToEmailAddress = toAddress, ToName = toName, Subject = subject, Body = message.GetHtml(), IsBodyHtml = true, IsHighPriority = highPriority, }; EmailMessageAgent agent = null; try { agent = new EmailMessageAgent(); agent.DispatchEmailMessage(msg); } finally { if (agent != null) agent.Close(); } }