Ejemplo n.º 1
0
        public MimeMessage CreateMail()
        {
            var mail = new MimeMessage();

            mail.From.Add(new MailboxAddress(GetFrom, GetFrom));
            if (!GetRecipients.IsNullOrEmpty())
            {
                mail.To.AddRange(GetRecipients.Select(to => new MailboxAddress(to, to)));
            }
            if (!GetCarbonCopies.IsNullOrEmpty())
            {
                mail.Cc.AddRange(GetCarbonCopies.Select(cc => new MailboxAddress(cc, cc)));
            }
            if (!GetBlindCarbonCopies.IsNullOrEmpty())
            {
                mail.Bcc.AddRange(GetBlindCarbonCopies.Select(bcc => new MailboxAddress(bcc, bcc)));
            }

            mail.Subject = GetSubject;
            var multipart = new Multipart {
                new TextPart("html")
                {
                    Text = GetBody
                }
            };

            GetAttachments?.ForEach(attachment => multipart.Add(attachment));
            mail.Body     = multipart;
            mail.Priority = GetMessagePriority;

            return(mail);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Recipients
 /// </summary>
 /// <param name="recipients"></param>
 /// <returns></returns>
 public Mail To(params string[] recipients)
 {
     if (recipients.IsNullOrEmpty())
     {
         return(this);
     }
     GetRecipients ??= new List <string>();
     GetRecipients.AddRange(recipients);
     return(this);
 }
Ejemplo n.º 3
0
        public MailMessage CreateMail()
        {
            var mail = new MailMessage
            {
                From         = new MailAddress(GetFrom),
                Subject      = GetSubject,
                IsBodyHtml   = GetIsBodyHtml,
                BodyEncoding = GetBodyEncoding,
                Body         = GetBody,
                Priority     = GetMailPriority
            };

            GetAttachments?.ForEach(attachment => mail.Attachments.Add(attachment));
            GetRecipients?.ForEach(to => mail.To.Add(new MailAddress(to)));
            GetCarbonCopies?.ForEach(cc => mail.CC.Add(new MailAddress(cc)));
            GetBlindCarbonCopies?.ForEach(bcc => mail.Bcc.Add(new MailAddress(bcc)));

            return(mail);
        }