コード例 #1
0
ファイル: Program.cs プロジェクト: r3utov/EmailBroker
 static void MessageProcessedHandler(object sender, MailSendResult result)
 {
     Console.WriteLine(
         $"({DateTime.Now}) [{(result.BooleanResult ? "OK" : "x")}] {result.ResultMessage}"
         );
     Console.WriteLine();
 }
コード例 #2
0
ファイル: MailSender.cs プロジェクト: r3utov/EmailBroker
        /// <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);
        }