Reputation: 4759
Im facing a little trouble when sending emails from ASP.NET (VB). Here is the code Im on
Using mm As New MailMessage("[email protected]", mc.mailTo)
If mc.mailCC.Trim <> "" Then
mm.CC.Add(mc.mailCC)
End If
If mc.mailBCC.Trim <> "" Then
mm.CC.Add(mc.mailBCC)
End If
mm.IsBodyHtml = True
mm.Subject = mc.mailSubject
mm.Body = b
Dim smtp As New SmtpClient()
Try
smtp.Send(mm)
Catch ex As SmtpException
gf.logArray(jA, ex.Message)
Dim statuscode As SmtpStatusCode
statuscode = ex.StatusCode
If statuscode = SmtpStatusCode.MailboxBusy Or statuscode = SmtpStatusCode.MailboxUnavailable Or statuscode = SmtpStatusCode.TransactionFailed Then
System.Threading.Thread.Sleep(5000)
smtp.Send(mm)
End If
End Try
End Using
The issue am having is. The mails are sending fine. but the body is showing as just HTML. Not rendering even I clearly specified mm.isBodyHTML=true. Any suggestions please...
THis is the message I got
Upvotes: 1
Views: 3692
Reputation: 1152
If you are using smtp for sending email you can add one parameter IsBodyHtml, I was facing same issue and fixed by setting IsBodyHtml=true and it works for me.
var fromAddress = new MailAddress("[email protected]", "Abc Noreply");
var toAddress = new MailAddress(email, "");
const string fromPassword = "acbsexample";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = emailBody,
IsBodyHtml=true
})
{
smtp.Send(message);
}
Upvotes: 2
Reputation: 199
I think that the main problem is in you html message body. Try send in message body only table with content, without DOCTYPE, head and other content.
Becouse mail agent render your message in already exist html page, so couldn`t render page in page a agent encode your message body as a string.
Upvotes: 0