您好我正在使用VB.net的SendGridMessage()对象通过SendGrid SMTP服务器发送电子邮件。
我有一个.mht文件,我想在邮件正文中发送...
我知道可以在邮件正文中发送纯HTML,但是当我读取MHT文件并将其放在邮件正文中时,它看起来像是这样搞砸了: 我希望看起来像这样:
这是我的代码:
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)
答案 0 :(得分:1)
您需要先将.MHT文件转换为常规HTML才能以这种方式使用它。 MHT包含元数据,其结构与HTML不同,因此您不能在需要HTML的参数中使用它。 MHT更像是一个MIME消息。如果您想通过MHT处理MIME,那么通过SMTP发送将更容易。