Example #1
0
        public static SmtpMessage Create(System.Net.Mail.MailMessage message, SmtpMessageCreateCondition condition)
        {
            SmtpMessage mg = new SmtpMessage();

            mg.Subject = condition.SubjectFormatter.CreateSubject(message);
            mg.From    = condition.Sender;
            mg.Sender  = condition.Sender;
            mg.ContentType.CharsetEncoding = message.BodyEncoding;
            mg.Priority = message.Priority.Cast();

            if (condition.BodyFormatter.IsHtml == true)
            {
                var html = condition.BodyFormatter.CreateBodyText(message);
                mg._BodyTextContent.LoadHtml(html);
            }
            else
            {
                mg.BodyText = condition.BodyFormatter.CreateBodyText(message);
            }
            AddMailAddress(message, condition.To, mg.To);
            AddMailAddress(message, condition.Cc, mg.Cc);
            AddMailAddress(message, condition.Bcc, mg.Bcc);

            if (condition.CopyAlternateViews == true)
            {
                foreach (var item in message.AlternateViews)
                {
                    var ct = new SmtpContent();
                    ct.LoadData(item.ContentStream);

                    ct.ContentTransferEncoding = item.TransferEncoding.Cast();
                    ct.ContentType.SetProperty(item.ContentType);

                    mg.Contents.Add(ct);
                }
            }
            if (condition.CopyAttachments == true)
            {
                foreach (var item in message.Attachments)
                {
                    var ct = new SmtpContent();
                    ct.LoadData(item.ContentStream);

                    ct.ContentTransferEncoding = item.TransferEncoding.Cast();
                    ct.ContentType.SetProperty(item.ContentType);
                    ct.ContentDisposition.SetProperty(item.ContentDisposition);
                    mg.Contents.Add(ct);
                }
            }
            return(mg);
        }
Example #2
0
        public static SmtpMessage Create(MailMessage message, SmtpMessageCreateCondition condition)
        {
            SmtpMessage mg = new SmtpMessage();

            mg.Subject = condition.SubjectFormatter.CreateSubject(message);
            mg.From    = condition.Sender;
            mg.Sender  = condition.Sender;
            mg.ContentType.SetProperty(message.ContentType);
            mg.ContentTransferEncoding = message.ContentTransferEncoding;
            if (condition.BodyFormatter.IsHtml == true)
            {
                mg._BodyTextContent.LoadHtml(condition.BodyFormatter.CreateBodyText(message));
            }
            else
            {
                mg.BodyText = condition.BodyFormatter.CreateBodyText(message);
            }

            AddMailAddress(message, condition.To, mg.To);
            AddMailAddress(message, condition.Cc, mg.Cc);
            AddMailAddress(message, condition.Bcc, mg.Bcc);

            if (condition.CopyContents == true)
            {
                foreach (var item in message.Contents)
                {
                    var ct = new SmtpContent();
                    ct.LoadData(item.RawData);
                    ct.ContentType.SetProperty(item.ContentType);
                    ct.ContentDisposition.SetProperty(item.ContentDisposition);
                    mg.Contents.Add(ct);
                }
            }

            return(mg);
        }