2016-07-21 66 views
0

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

我知道这是可能在邮件正文中发送纯HTML,但是当我读了MHT文件,并把它放在邮件正文,似乎都搞砸这样的: Email mht ,我想看看它是这样的: MHT File

这是我的代码:

Dim myMsg As New SendGridMessage() 

myMsg.AddTo("[email protected]") 
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) 

回答

1

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

相关问题