private async Task SendMailAsync(EmailMessage message) { var client = new SmtpClient { Host = Host, Timeout = Timeout, Port = PortNumber, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(MailAccount, Password) }; var mail = new MailMessage(); mail.To.Add(new MailAddress(message.Destination)); mail.From = new MailAddress(SendAddress, DisplayName); mail.Subject = message.Subject; mail.Body = message.Body; mail.BodyEncoding = Encoding.UTF8; try { await client.SendMailAsync(mail); } catch (Exception ex) { Trace.TraceError(ex.Message + " SendGrid probably not configured correctly."); } }
private async Task SendEmailAsync(EmailMessage message) { dynamic sendGrid = new SendGridAPIClient(MailAccount); var from = new Email(SendAddress); var to = new Email(message.Destination); var content = new Content("text/plain", message.Body); var mail = new Mail(from, message.Subject, to, content); try { dynamic response = await sendGrid.client.mail.send.post(requestBody: mail.Get()); } catch (Exception ex) { Trace.TraceError(ex.Message + " SendGrid probably not configured correctly."); } }
private async void SendMailBtn_Click(object sender, EventArgs e) { var info = new MailServiceInfo { Host = "smtp.sendgrid.net", DisplayName = "Joe Bloggs", MailAccount = "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", Password = "******", PortNumber = 10000, SendAddress = "*****@*****.**", Timeout = 25000 }; var message = new EmailMessage { Body = "This email shows that the debug code is working", Destination = "*****@*****.**", Subject = "Test Email" }; var service = new EmailService(info); await service.SendAsync(message); }
public async Task SendAsync(EmailMessage message) { await SendEmailAsync(message); }