예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
 }
예제 #4
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);
 }