public MailMessage CreateMailMessageObject(EmailModel email)
        {
            var body        = email.Message;
            var mailMessage = new MailMessage();

            foreach (string emailTo in email.EmailsTo)
            {
                mailMessage.To.Add(new MailAddress(emailTo));
            }

            mailMessage.From       = new MailAddress(EmailHelper.EmailInfo.EmailSender);
            mailMessage.Subject    = email.Subject;
            mailMessage.Body       = body;
            mailMessage.IsBodyHtml = true;

            if (email.FileNameAttachments != null)
            {
                mailMessage.AddAttachments(email.FileNameAttachments);
            }

            if (email.StreamAttachments != null)
            {
                mailMessage.AddAttachments(email.StreamAttachments);
            }

            return(mailMessage);
        }
Пример #2
0
 public static void Send(List <Address> mailFromList, List <Address> targetEmails,
                         NunitGoTest nunitGoTest, string screenshotsPath, bool addLinks,
                         bool isEventEmail = false, string eventName = "", TestEvent previousRunEvent = null)
 {
     foreach (var address in targetEmails)
     {
         var fromMails = mailFromList;
         var success   = false;
         while (!success && fromMails.Any())
         {
             using (var message = new MailMessage
             {
                 IsBodyHtml = true,
                 Subject = MailGenerator.GetMailSubject(nunitGoTest, isEventEmail, eventName),
                 Body = MailGenerator.GetMailBody(nunitGoTest, addLinks, isEventEmail, eventName, previousRunEvent)
             })
             {
                 var attachments = MailGenerator.GetAttachmentsFromScreenshots(nunitGoTest, screenshotsPath);
                 message.AddAttachments(attachments);
                 success = SingleSend(fromMails.First(), address, message);
                 if (!success)
                 {
                     fromMails = fromMails.Skip(1).ToList();
                 }
             }
         }
     }
 }
Пример #3
0
        public bool Send(SendMailRequest request)
        {
            if (request != null)
            {
                MailMessage mail = new MailMessage();

                mail.SetRecipients(request.MailTo, request.MailCC, request.MailBCC);

                mail.From   = From;
                mail.Sender = Sender;

                mail.Subject         = request.Subject;
                mail.SubjectEncoding = Encoding.UTF8;

                mail.IsBodyHtml   = request.IsBodyHtml;
                mail.BodyEncoding = Encoding.Unicode;
                mail.Body         = request.Body;

                mail.AddAttachments(request.Attachments, ResourceResolver);

                mail.AddHtmlView(request.Body, request.HtmlResources, ResourceResolver);

                return(Send(mail));
            }
            throw new Exception("Request is null");
        }