static void MessageProcessedHandler(object sender, MailSendResult result) { Console.WriteLine( $"({DateTime.Now}) [{(result.BooleanResult ? "OK" : "x")}] {result.ResultMessage}" ); Console.WriteLine(); }
/// <summary> /// Отправка письма /// </summary> public async Task <MailSendResult> SendMailAsync(MailMessageData emailMessage) { MailSendResult result; MailMessage mailMessage = emailMessage.GetMailMessage(); try { using (var client = CreateSmtpClient(GetConfig())) { await client.SendMailAsync(mailMessage); string resultMessage = $"Письмо отправлено на {string.Join(",", mailMessage.To)}."; result = new MailSendResult(mailMessage, true, resultMessage); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result = new MailSendResult(mailMessage, false, $"Ошибка отправки: {ex.Message}"); } finally { Thread.Sleep(SendTimeout); } return(result); }