1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
public static async Task SendMailAsync(EMailConfig config, string toMail, string subj, string bodys) { string host = config.SMTPService; int port = config.Port; string from = config.FromEmail; string to = toMail; string userName = config.UserName; string password = config.Password;
var message = new MimeMessage(); message.From.Add(new MailboxAddress(from)); message.To.AddRange(new MailboxAddress[] { new MailboxAddress(to) }); message.Subject = subj; message.Body = new TextPart(TextFormat.Html) { Text = bodys }; SmtpClient client = new SmtpClient(); await client.ConnectAsync(host, port, port == 465); await client.AuthenticateAsync(userName, password); await client.SendAsync(message); await client.DisconnectAsync(true); client.MessageSent += new EventHandler<MailKit.MessageSentEventArgs>((sender, e) => { System.Console.WriteLine(e.Response); }); }
|