I've created code to send e-mail out but I have noticed that when it is received in MS Outlook in my test, if the message is in preview state, meaning the USER see it as a new message in the list, there are HTML tags in the message. But as soon as the USER
clicks on the message to read, the HTML tags disappear.
It doesn't affect the e-mail layout from the USER perspective, but I am wondering what am I doing wrong sending the e-mail in my code and having the HTML tags displayed in preview. Here is part of my code:
Dim MailContent As String = "The following information has been submitted to your GVNW SOA For Port Modification." + "<br/><br/>"
MailContent += "Ref Id: " & PassPid & "<br/><br/>"
MailContent += "Porting Option: " & PortingOptionChoiceDescription & "<br/>"
MailContent += "Simple Port: " & SimplePortTxt & "<br/>"
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/plain")
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/html")
Dim fromAddress As New MailAddress("No-Reply")
Dim m As New MailMessage()
m.From = fromAddress
' This e-mail address will be used to the user logged in.
m.CC.Add(New MailAddress(UserEmail))
m.To.Add(New MailAddress(ConfigurationManager.AppSettings("admin")))
m.Subject = " (Modify Time) - " + Profile.companyName.ToString()
m.AlternateViews.Add(plainView)
m.AlternateViews.Add(htmlView)
m.Body = MailContent
m.IsBodyHtml = True
Dim smtpClient As SmtpClient = New SmtpClient()
' Enable SSL if applicable by provider
smtpClient.EnableSsl = True
' Send the email
smtpClient.Send(m)
Anyone have thoughts?
Please remember to click Mark as Answer if my post was helpful.
It appears this was the culprit. I am not totally familiar why this is the case but when I remove this part of the code (please refer to my original post), Outlook does not display the HTML tags in the preview list of the e-mail received.
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/plain")
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/html")
m.AlternateViews.Add(plainView)
m.AlternateViews.Add(htmlView)
Anyone have thoughts if this code that I will remarked out is necessary? I am still able to view the e-mails properly in HTML format in OUTLOOK and web based YAHOO account.
Please remember to click Mark as Answer if my post was helpful.
imchaz
Member
350 Points
360 Posts
Sending E-mail - Outook preview email with HTML tags
Jan 07, 2013 09:12 PM|LINK
I've created code to send e-mail out but I have noticed that when it is received in MS Outlook in my test, if the message is in preview state, meaning the USER see it as a new message in the list, there are HTML tags in the message. But as soon as the USER clicks on the message to read, the HTML tags disappear.
It doesn't affect the e-mail layout from the USER perspective, but I am wondering what am I doing wrong sending the e-mail in my code and having the HTML tags displayed in preview. Here is part of my code:
Dim MailContent As String = "The following information has been submitted to your GVNW SOA For Port Modification." + "<br/><br/>" MailContent += "Ref Id: " & PassPid & "<br/><br/>" MailContent += "Porting Option: " & PortingOptionChoiceDescription & "<br/>" MailContent += "Simple Port: " & SimplePortTxt & "<br/>" Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/plain") Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/html") Dim fromAddress As New MailAddress("No-Reply") Dim m As New MailMessage() m.From = fromAddress ' This e-mail address will be used to the user logged in. m.CC.Add(New MailAddress(UserEmail)) m.To.Add(New MailAddress(ConfigurationManager.AppSettings("admin"))) m.Subject = " (Modify Time) - " + Profile.companyName.ToString() m.AlternateViews.Add(plainView) m.AlternateViews.Add(htmlView) m.Body = MailContent m.IsBodyHtml = True Dim smtpClient As SmtpClient = New SmtpClient() ' Enable SSL if applicable by provider smtpClient.EnableSsl = True ' Send the email smtpClient.Send(m)Anyone have thoughts?
asawaf
Member
350 Points
75 Posts
Re: Sending E-mail - Outook preview email with HTML tags
Jan 08, 2013 08:49 AM|LINK
My simplest tip: If you set the mail object body type to HTML, it should correctly and automatically be translated in Outlook:
newEmail.IsBodyHtml = True
http://afsawaf.blogspot.com/2012/08/sending-e-mails-with-attachments-using.html
Please mark as "Answer" if this helped you.
ManikandanUl...
Participant
850 Points
253 Posts
Re: Sending E-mail - Outook preview email with HTML tags
Jan 08, 2013 08:52 AM|LINK
Pls refer below link
http://afsawaf.blogspot.com/2012/08/sending-e-mails-with-attachments-using.html
Click "…Mark As Answer" if my reply helpful....
imchaz
Member
350 Points
360 Posts
Re: Sending E-mail - Outook preview email with HTML tags
Jan 08, 2013 06:49 PM|LINK
Thank you for your reply but in my original post, I do include that peice of code already.
imchaz
Member
350 Points
360 Posts
Re: Sending E-mail - Outook preview email with HTML tags
Jan 08, 2013 06:50 PM|LINK
Thank you for your reply but I don't know what I could be doing any different from the link you provided in comparison of what I originally coded.
imchaz
Member
350 Points
360 Posts
Re: Sending E-mail - Outook preview email with HTML tags
Jan 08, 2013 07:47 PM|LINK
It appears this was the culprit. I am not totally familiar why this is the case but when I remove this part of the code (please refer to my original post), Outlook does not display the HTML tags in the preview list of the e-mail received.
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/plain") Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(MailContent, Nothing, "text/html") m.AlternateViews.Add(plainView) m.AlternateViews.Add(htmlView)Anyone have thoughts if this code that I will remarked out is necessary? I am still able to view the e-mails properly in HTML format in OUTLOOK and web based YAHOO account.