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



我有一个原始电子邮件(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设置为

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

原始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>

转换消息后,我执行了以下操作:

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

这对这种特殊情况很好,但。。。

  • 它将永远是信息。备选视图(0)
  • 我更希望ToMailMessage()直接进行转换

相关内容

  • 没有找到相关文章

最新更新