Esempio n. 1
0
        /// <summary>
        /// Sends an email message and returns a success/failure flag.
        /// </summary>
        /// <param name="fields">An <see cref="EmailFields"/> instance with required parameters to send an email.</param>
        /// <returns><c>true</c> if the system was able to successfully send an email, otherwise <c>false</c>.</returns>
        public bool SendMessage(EmailFields fields)
        {
            bool result = false;

            result = SendMessage(GetMailMessage(fields));
            return(result);
        }
Esempio n. 2
0
        public MailMessage GetMailMessage(EmailFields fields)
        {
            MailMessage result = new MailMessage();

            result.From       = new MailAddress(fields.Sender);
            result.IsBodyHtml = fields.IsHtml;
            result.Priority   = fields.Priority;
            result.Subject    = fields.Subject;
            result.Body       = fields.Body;
            result.Sender     = new MailAddress(fields.Sender);

            foreach (Attachment attachment in fields.Attachments)
            {
                result.Attachments.Add(attachment);
            }

            foreach (string recipient in fields.Recipients)
            {
                if (!string.IsNullOrEmpty(recipient))
                {
                    result.To.Add(new MailAddress(recipient));
                }
            }

            foreach (string ccrecipient in fields.CcRecipients)
            {
                if (!string.IsNullOrEmpty(ccrecipient))
                {
                    result.CC.Add(new MailAddress(ccrecipient));
                }
            }

            foreach (string bccrecipient in fields.BccRecipients)
            {
                if (!string.IsNullOrEmpty(bccrecipient))
                {
                    result.Bcc.Add(new MailAddress(bccrecipient));
                }
            }

            foreach (string replyto in fields.ReplyTo)
            {
                if (!string.IsNullOrEmpty(replyto))
                {
                    result.ReplyToList.Add(new MailAddress(replyto));
                }
            }

            return(result);
        }