Esempio n. 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));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a mailer object from template.  Quick compose to send to one recipient only.
        /// </summary>
        /// <param name="orgUnitID"></param>
        /// <param name="mailTemplateCode"></param>
        /// <param name="messageTokenValues"></param>
        /// <param name="emailTo"></param>
        /// <param name="subjectTokenValues"></param>
        /// <param name="emailCC"></param>
        /// <param name="emailBcc"></param>
        public void Compose(string Link, string emailTo, string emailCC = null, string emailBcc = null, List <MailerAttachment> attachments = null)
        {
            MailerRecipient        to     = new MailerRecipient(emailTo);
            List <MailerRecipient> toList = new List <MailerRecipient>();

            toList.Add(to);
            List <MailerRecipient> ccList = null;

            if (!string.IsNullOrEmpty(emailCC))
            {
                MailerRecipient cc = new MailerRecipient(emailCC);
                if (ccList == null)
                {
                    ccList = new List <MailerRecipient>();
                }
                ccList.Add(cc);
            }
            List <MailerRecipient> bccList = null;

            if (!string.IsNullOrEmpty(emailBcc))
            {
                MailerRecipient bcc = new MailerRecipient(emailBcc);
                if (bccList == null)
                {
                    bccList = new List <MailerRecipient>();
                }
                bccList.Add(bcc);
            }
            Compose(Link, toList, ccList, bccList, attachments);
        }
Esempio n. 3
0
 /// <summary>
 /// Use this constructor for OrgUnit Level emails sent on behalf of OrgUnit
 /// </summary>
 /// <param name="orgUnit"></param>
 public Mailer(string FromEmail, string FromEmailDisplayName)
 {
     LoadSettingsFromEnvironment();
     if (MailerRecipient.IsValidEmail(FromEmail))
     {
         _fromEmailAddress = FromEmail;
         _replyTo          = FromEmail;
     }
     if (!string.IsNullOrEmpty(FromEmailDisplayName))
     {
         _fromDisplayName = FromEmailDisplayName;
     }
     _mMail       = new MailMessage();
     _attachments = new List <MailerAttachment>();
 }
Esempio n. 4
0
        public static List <MailAddress> ConvertToMailAddressList(List <MailerRecipient> recipientList)
        {
            List <MailAddress> addressList = null;

            if (recipientList != null)
            {
                addressList = new List <MailAddress>();
                foreach (MailerRecipient recipient in recipientList)
                {
                    MailAddress address = MailerRecipient.ConvertToMailAddress(recipient);
                    addressList.Add(address);
                }
            }
            return(addressList);
        }
Esempio n. 5
0
        public static MailAddress ConvertToMailAddress(MailerRecipient recipient)
        {
            MailAddress mailAddress;

            if (!string.IsNullOrEmpty(recipient.EmailAddress) && !string.IsNullOrEmpty(recipient.RecipientName))
            {
                mailAddress = new MailAddress(recipient.EmailAddress, recipient.RecipientName);
            }
            else if (!string.IsNullOrEmpty(recipient.EmailAddress))
            {
                mailAddress = new MailAddress(recipient.EmailAddress);
            }
            else
            {
                mailAddress = null;
            }
            return(mailAddress);
        }
Esempio n. 6
0
 public static MailAddress ConvertToMailAddress(MailerRecipient recipient)
 {
     MailAddress mailAddress;
     if (!string.IsNullOrEmpty(recipient.EmailAddress) && !string.IsNullOrEmpty(recipient.RecipientName))
     {
         mailAddress = new MailAddress(recipient.EmailAddress, recipient.RecipientName);
     }
     else if (!string.IsNullOrEmpty(recipient.EmailAddress))
     {
         mailAddress = new MailAddress(recipient.EmailAddress);
     }
     else
     {
         mailAddress = null;
     }
     return mailAddress;
 }
Esempio n. 7
0
 /// <summary>
 /// Creates a mailer object from template.  Quick compose to send to one recipient only. 
 /// </summary>
 /// <param name="orgUnitID"></param>
 /// <param name="mailTemplateCode"></param>
 /// <param name="messageTokenValues"></param>
 /// <param name="emailTo"></param>
 /// <param name="subjectTokenValues"></param>
 /// <param name="emailCC"></param>
 /// <param name="emailBcc"></param>
 public void Compose( string Link, string emailTo, string emailCC = null, string emailBcc = null, List<MailerAttachment> attachments = null)
 {
     MailerRecipient to = new MailerRecipient(emailTo);
     List<MailerRecipient> toList = new List<MailerRecipient>();
     toList.Add(to);
     List<MailerRecipient> ccList = null;
     if (!string.IsNullOrEmpty(emailCC))
     {
         MailerRecipient cc = new MailerRecipient(emailCC);
         if (ccList == null) ccList = new List<MailerRecipient>();
         ccList.Add(cc);
     }
     List<MailerRecipient> bccList = null;
     if (!string.IsNullOrEmpty(emailBcc))
     {
         MailerRecipient bcc = new MailerRecipient(emailBcc);
         if (bccList == null) bccList = new List<MailerRecipient>();
         bccList.Add(bcc);
     }
     Compose(Link, toList, ccList, bccList, attachments);
 }