public static HigLabo.Net.Smtp.SmtpMessage ToSystemHigLaboSmtpMessage(this MailMessage msg) { var readyMessage = new HigLabo.Net.Smtp.SmtpMessage(); readyMessage.Subject = msg.Subject; readyMessage.Header.Add(new HigLabo.Net.InternetTextMessage.Field("Message-ID", msg.MessageID)); if (msg.From != null) { readyMessage.From = msg.From.ToHigLaboMailAddress(); } else if (msg.Sender != null) { readyMessage.From = msg.Sender.ToHigLaboMailAddress(); } foreach (var t in msg.To) { readyMessage.To.Add(t.ToHigLaboMailAddress()); } foreach (var c in msg.CC) { readyMessage.Cc.Add(c.ToHigLaboMailAddress()); } foreach (var b in msg.BCC) { readyMessage.Bcc.Add(b.ToHigLaboMailAddress()); } readyMessage.HeaderTransferEncoding = HigLabo.Net.Mail.TransferEncoding.Base64; readyMessage.ContentTransferEncoding = HigLabo.Net.Mail.TransferEncoding.Base64; readyMessage.IsHtml = msg.IsBodyHtml; readyMessage.BodyText = addMessageIDStampToBody(msg); foreach (var a in msg.Attachments) { var ct = new HigLabo.Net.Smtp.SmtpContent(); ct.Name = a.Name; ct.FileName = a.Name; ct.ContentTransferEncoding = HigLabo.Net.Mail.TransferEncoding.Base64; ct.LoadData(a.MimeType, a.Body); readyMessage.Contents.Add(ct); // readyMessage.Attachments.Add(a.ToSytemNetMailAttachment()); } // поддържаме един и същи енкодинг на subject / body readyMessage.ContentEncoding = msg.Encoding.ToEncoding(); return(readyMessage); }
/// このインスタンスの値を元に、SmtpMessageクラスのインスタンスを生成します。 /// <summary> /// Create SmtpMessage instance with this instance value. /// このインスタンスの値を元に、SmtpMessageクラスのインスタンスを生成します。 /// </summary> /// <returns></returns> public Smtp.SmtpMessage CreateSmtpMessage() { Smtp.SmtpMessage mg = new HigLabo.Net.Smtp.SmtpMessage(); Field f = null; mg.To.AddRange(MailAddress.CreateMailAddressList(this.To)); mg.Cc.AddRange(MailAddress.CreateMailAddressList(this.Cc)); for (int i = 0; i < this.Header.Count; i++) { f = this.Header[i]; if (String.IsNullOrEmpty(f.Value) == true) { continue; } if (f.Key.ToLower() == "to" || f.Key.ToLower() == "cc") { continue; } mg[f.Key] = MailParser.DecodeFromMailHeaderLine(f.Value); } for (int i = 0; i < this.ContentType.Fields.Count; i++) { f = this.ContentType.Fields[i]; mg.ContentType.Fields.Add(new Field(f.Key, MailParser.DecodeFromMailHeaderLine(f.Value))); } for (int i = 0; i < this.ContentDisposition.Fields.Count; i++) { f = this.ContentDisposition.Fields[i]; mg.ContentDisposition.Fields.Add(new Field(f.Key, MailParser.DecodeFromMailHeaderLine(f.Value))); } mg.BodyText = this.BodyText; for (int i = 0; i < this.Contents.Count; i++) { mg.Contents.Add(this.Contents[i].CreateSmtpContent()); } return(mg); }