Esempio n. 1
0
        public MailMessage GetMailMessage()
        {
            var mailMessage = new MailMessage()
            {
                IsBodyHtml   = IsBodyHtml,
                Body         = Body,
                Subject      = Subject,
                BodyEncoding = BodyEncoding,
                DeliveryNotificationOptions = DeliveryNotificationOptions,
                Priority        = Priority,
                SubjectEncoding = SubjectEncoding,
            };

            if (From != null)
            {
                mailMessage.From = From.GetMailAddress();
            }

            foreach (var mailAddress in To)
            {
                mailMessage.To.Add(mailAddress.GetMailAddress());
            }

            foreach (var mailAddress in CC)
            {
                mailMessage.CC.Add(mailAddress.GetMailAddress());
            }

            foreach (var mailAddress in Bcc)
            {
                mailMessage.Bcc.Add(mailAddress.GetMailAddress());
            }

            foreach (var attachment in Attachments)
            {
                mailMessage.Attachments.Add(attachment.GetAttachment());
            }

            Headers.CopyTo(mailMessage.Headers);

            foreach (var mailAddress in ReplyToList)
            {
                mailMessage.ReplyToList.Add(mailAddress.GetMailAddress());
            }

            if (Sender != null)
            {
                mailMessage.Sender = Sender.GetMailAddress();
            }

            foreach (var alternateView in AlternateViews)
            {
                mailMessage.AlternateViews.Add(alternateView.GetAlternateView());
            }

            return(mailMessage);
        }