在正文电子邮件中发送 mht 文件

Send mht file in body email

您好,我正在使用带有 VB.net 的 SendGridMessage() 对象通过 SendGrid SMTP 服务器发送电子邮件。
我有一个 .mht 文件,我想在邮件正文中发送...

I know that is possible to send pure html in a mail body but when i read the MHT file and put it on the mail body, it appears all messed up like this: And i wanted to look it like this:

这是我的代码:

Dim myMsg As New SendGridMessage()

myMsg.AddTo("email@email.com")
myMsg.From = New MailAddress(ApiEmail, ApiUserName)
myMsg.Subject = "Test with MHT file"
myMsg.Html = ""

Dim fso As New FileSystemObject
Dim ts As TextStream

'Open file.
ts = fso.OpenTextFile(sPath)
'Loop while not at the end of the file.
Do While Not ts.AtEndOfStream
myMsg.Html += ts.ReadLine

Loop
'Close the file.
ts.Close()

Dim credentials = New NetworkCredential(ApiUser, ApiKey)
Dim transportWeb = New Web(credentials)
transportWeb.DeliverAsync(myMsg)

您需要先将 .MHT 文件转换为常规 HTML 才能以这种方式使用它。 MHT 包含元数据,其结构不同于 HTML,因此您不能在需要 HTML 的参数中使用它。 MHT 更像是 MIME 消息。如果你想通过 MHT 处理 MIME,那么通过 SMTP 发送会更容易。