Hello I am using SendGridMessage() object with VB.net to send emails through SendGrid SMTP server.
I have a .mht file that i want to send in the mail body...
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:
This is my code:
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)
You need to convert the .MHT file to regular HTML first to use it in this way. MHT contains metadata and is structured differently than HTML, so you can't use it in a parameter that expects HTML. MHT is more like a MIME message. If you want to deal with MIME via MHT, then sending over SMTP will be easier.