【问题标题】:Converting OpenPop.NET HTML message to System.Net.Mail.MailMessage becomes text/plain将 OpenPop.NET HTML 消息转换为 System.Net.Mail.MailMessage 变为 text/plain
【发布时间】:2014-11-09 15:54:45
【问题描述】:

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

【问题讨论】:

    标签: vb.net mailmessage openpop


    【解决方案1】:

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

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

    这适用于这种特殊情况,但是...

    • 会一直是 message.AlternateViews(0) 吗?
    • 我希望ToMailMessage() 直接进行转换

    【讨论】:

    • 我也不清楚这个文档。 hpop.sourceforge.net/documentation/… 我认为最后一行 HTML content will be treated as the preferred view for the Body. Plain text content will be used for the Body when HTML is not available. 正是您(和我)更喜欢的:自动转换。 (自动弹出 nuget 2.0.6.x)
    猜你喜欢
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 2010-12-22
    • 2014-08-18
    • 2011-12-08
    • 2017-03-05
    相关资源
    最近更新 更多