Пример #1
0
        public void Compose(string subject, string body, List <MailerRecipient> toList, bool isBodyHtml = true, List <MailerAttachment> attachments = null, List <MailerRecipient> ccList = null, List <MailerRecipient> bccList = null, MailerPriorityFlag priority = MailerPriorityFlag.Normal)
        {
            _mMail        = new MailMessage();
            _mMail.Sender = new MailAddress(_senderEmailAdress);
            if (!string.IsNullOrEmpty(_fromEmailAddress))
            {
                if (!string.IsNullOrEmpty(_fromDisplayName))
                {
                    _mMail.From = new MailAddress(_fromEmailAddress, _fromDisplayName);
                }
                else
                {
                    _mMail.From = new MailAddress(_fromEmailAddress);
                }
            }
            if (!string.IsNullOrEmpty(_replyTo))
            {
                MailAddress replyToAddress;
                if (!string.IsNullOrEmpty(_fromDisplayName))
                {
                    replyToAddress = new MailAddress(_replyTo, _fromDisplayName);
                }
                else
                {
                    replyToAddress = new MailAddress(_replyTo);
                }
                _mMail.ReplyToList.Add(replyToAddress);
            }
            MailerRecipient.ConvertToMailAddressList(toList).ForEach(r => _mMail.To.Add(r));
            if (ccList != null)
            {
                MailerRecipient.ConvertToMailAddressList(ccList).ForEach(r => _mMail.CC.Add(r));
            }
            if (bccList != null)
            {
                MailerRecipient.ConvertToMailAddressList(bccList).ForEach(r => _mMail.Bcc.Add(r));
            }
            switch (priority)
            {
            case MailerPriorityFlag.High:
                _mMail.Priority = MailPriority.High;
                break;

            case MailerPriorityFlag.Low:
                _mMail.Priority = MailPriority.Low;
                break;

            default:
                _mMail.Priority = MailPriority.Normal;
                break;
            }
            _mMail.Subject    = subject;
            _mMail.Body       = body;
            _mMail.IsBodyHtml = isBodyHtml;

            if (attachments != null)
            {
                MailerAttachment.ConvertToAttachmentList(attachments).ForEach(a => _mMail.Attachments.Add(a));
            }
        }
Пример #2
0
        public static List <Attachment> ConvertToAttachmentList(List <MailerAttachment> mailerAttachmentList)
        {
            List <Attachment> attachmentList = null;

            if (mailerAttachmentList != null)
            {
                attachmentList = new List <Attachment>();
                mailerAttachmentList.ForEach(ma => attachmentList.Add(MailerAttachment.ConvertToAttachment(ma)));
            }
            return(attachmentList);
        }
Пример #3
0
        public static Attachment ConvertToAttachment(MailerAttachment mailerAttachment)
        {
            Attachment attachment = null;

            if (mailerAttachment != null)
            {
                attachment = new Attachment(mailerAttachment.Content, mailerAttachment.FileName);
                try
                {
                    if (!string.IsNullOrEmpty(mailerAttachment.MimeType))
                    {
                        attachment.ContentType = new System.Net.Mime.ContentType(mailerAttachment.MimeType);
                    }
                }
                catch (Exception e)
                {
                }
            }
            return(attachment);
        }
Пример #4
0
 public static Attachment ConvertToAttachment(MailerAttachment mailerAttachment)
 {
     Attachment attachment = null;
     if (mailerAttachment != null)
     {
         attachment = new Attachment(mailerAttachment.Content, mailerAttachment.FileName);
         try
         {
             if (!string.IsNullOrEmpty(mailerAttachment.MimeType))
                 attachment.ContentType = new System.Net.Mime.ContentType(mailerAttachment.MimeType);
         }
         catch (Exception e)
         {
            
         }
     }
     return attachment;
 }