Example #1
0
        public async Task <MailSendResult> SendMailAsync(MailMessageData emailMessage)
        {
            Console.WriteLine($"EmailRabbitMQProcessor SendMailAsync method  => Calısma zamanı: {DateTime.Now.ToShortTimeString()}");

            MailSendResult result;
            MailMessage    mailMessage = emailMessage.GetMailMessage();

            mailMessage.From = new MailAddress(_smtpConfiguration.User);
            try
            {
                using (var client = CreateSmtpClient(_smtpConfiguration.GetSmtpConfig()))
                {
                    await client.SendMailAsync(mailMessage);

                    string resultMessage = $"donus mesajı metni  {string.Join(",", mailMessage.To)}.";
                    result = new MailSendResult(mailMessage, true, resultMessage);
                    Console.WriteLine($"EmailRabbitMQProcessor running => resultMessage to:{ mailMessage.To}");
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                result = new MailSendResult(mailMessage, false, $"Hata: {ex.Message}");
            }
            finally
            {
                Thread.Sleep(MailConsts.SendTimeout);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Имитация отправки письма
        /// </summary>
        public async Task <MailSendResult> SendMailAsync(MailMessageData emailMessage)
        {
            Thread.Sleep(SendTimeout);
            var result = await Task.Factory.StartNew <MailSendResult>(() => {
                string resultMessage = $"[Test] Письмо отправлено на {emailMessage.To}.";
                return(new MailSendResult(emailMessage.GetMailMessage(), true, resultMessage));
            });

            return(result);
        }
Example #3
0
        /// <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);
        }