Exemple #1
0
        private async Task SendMailAsync(MailListSubscription reg, string fullTemplateName)
        {
            MailboxAddress fromAddress = new MailboxAddress(reg.MailList.FromEmailName, reg.MailList.FromEmailAddress);

            MailboxAddress[] toAddresses = new MailboxAddress[] { MailboxAddress.Parse(reg.EmailAddress) };
            MimeMessage      message     = await mailCreator.CreateMailAsync(fullTemplateName, reg, GetViewBagForTemplate(), null);

            await mailSender.SendMailAsync(GetMessages(reg, message, fromAddress, toAddresses), false);
        }
Exemple #2
0
 private async IAsyncEnumerable <MailToSend> GetMessages(IEnumerable <MailListSubscription> subs, IMailCreator mailCreator, MailList list,
                                                         ExpandoObject viewBag, string fullTemplateName, Action <MailListSubscription, string> callback)
 {
     foreach (MailListSubscription sub in subs)
     {
         MimeMessage message;
         try
         {
             message = await mailCreator.CreateMailAsync(fullTemplateName, sub, viewBag, null);
         }
         catch (Exception ex)
         {
             MailDemonLog.Error(ex);
             continue;
         }
         message.From.Clear();
         message.To.Clear();
         if (string.IsNullOrWhiteSpace(list.FromEmailName))
         {
             message.From.Add(MailboxAddress.Parse(list.FromEmailAddress));
         }
         else
         {
             message.From.Add(new MailboxAddress(list.FromEmailName, list.FromEmailAddress));
         }
         message.To.Add(MailboxAddress.Parse(sub.EmailAddress));
         yield return(new MailToSend {
             Subscription = sub, Message = message, Callback = callback
         });
     }
 }