private static async Task Main() { var emailer = new Email(); var emailMessage = new EmailSend { Body = "<h1>Hi I am cool async email<h1>", From = "*****@*****.**", Subject = "Test Email from async", To = "*****@*****.**" }; await emailer.SendAsync(emailMessage); }
private static MailMessage BuildMessage(EmailSend email) { var mailMessage = new MailMessage { From = new MailAddress(email.From), Subject = email.Subject, Body = email.Body, IsBodyHtml = true }; mailMessage.To.Add(new MailAddress(email.To)); return(mailMessage); }
public int Send(EmailSend email) { using (var message = BuildMessage(email)) using (var client = new SmtpClient { Host = Host, Port = Port, Timeout = TimeOut }) { client.Send(message); } return(0); }
public async Task <int> SendAsync(EmailSend email) { using (var message = BuildMessage(email)) using (var client = new SmtpClient { Host = Host, Port = Port, Timeout = TimeOut }) { await client.SendMailAsync(message).ConfigureAwait(false); } return(0); }