将OpenPop.NET HTML消息转换为System.Net.Mail.MailMessage将变为text / plain

时间:2014-09-16 02:04:41

标签: vb.net mailmessage openpop

我有一个原始电子邮件(MIME文本),我用OpenPop.Net解析然后转换为System.Net.Mail.MailMessage

Dim message As MailMessage
Dim openPopMsg As New OpenPop.Mime.Message(System.Text.Encoding.ASCII.GetBytes(mimeText))
message = openPopMsg.ToMailMessage()

Dim Client As SmtpClient
Client = New SmtpClient(account.Server, account.Port)
Client.Credentials = New System.Net.NetworkCredential(account.User, account.Password)
Client.EnableSsl = account.UseSSL
Client.DeliveryMethod = SmtpDeliveryMethod.Network
Client.Send(message)
Client.Dispose()

发送电子邮件,附件发送正常,等等。 唯一的问题是电子邮件的内容应该是text / html,但我收到HTML为text / plain。

message.IsBodyHtml设置为 True

如何更改特定部分的内容类型或更好地进行正确的转换?

原始的mime文本看起来像这样(这只是多部分电子邮件的一部分):

----boundary_27_d254c44c-5b54-4df3-ac69-ef73c8b0158b
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3D=
utf-8"><html><header><style>p{margin-top: 0;margin-bottom: 0;line=
-height: 100%}ul,li{padding: 0px;margin: 0px;margin-top: 0;margin=
-bottom: 0}</style></header><body><p style=3D"text-align:left;"><=
span style=3D"font-bold:false;color:rgb(0,0,0);"><font face=3D"Ar=
ial" style=3D"font-size:12pt;" >Mira este es el subjetct: This is=
 an email test.</font></span></p><BR><BR><BR></body></html>

发送的电子邮件包含以下mime文本:

----boundary_3_d722cdce-a270-41b5-aa4e-33aa9131512a
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3D=
utf-8"><html><header><style>p{margin-top: 0;margin-bottom: 0;line=
-height: 100%}ul,li{padding: 0px;margin: 0px;margin-top: 0;margin=
-bottom: 0}</style></header><body><p style=3D"text-align:left;"><=
span style=3D"font-bold:false;color:rgb(0,0,0);"><font face=3D"Ar=
ial" style=3D"font-size:12pt;" >Mira este es el subjetct: This is=
 an email test.</font></span></p><BR><BR><BR></body></html>

1 个答案:

答案 0 :(得分:1)

转换邮件后,我执行了以下操作:

message.AlternateViews(0).ContentType.MediaType = "text/html"

这适用于这个特殊情况,但......

  • 它是否始终是message.AlternateViews(0)?
  • 我希望ToMailMessage()直接进行转换