We help IT Professionals succeed at work.

Sending HTML Formatted Email from ASP.NET

386 Views
Last Modified: 2017-05-01
I'm trying to send email from my ASP.NET VB web page using Outlook. I can get the message to open  but the body will not format the HTML, I've tried using both BodyFormat = OlBodyFormat.olFormatHTML & HTMLBody = True, but still no joy.

here's my code:

Imports Outlook

Partial Class _Default
    Inherits System.Web.UI.Page

    Private Sub cmdSend_Click(sender As Object, e As EventArgs) Handles cmdSend.Click

        ' Create Outlook App and Connect
        Dim OutlookApplication As New Application()

        ' create the MailItem which we want to send 
        ' Use a try catch to make sure Outlook is running
        Try
            Dim email As MailItem = DirectCast(OutlookApplication.CreateItem(OlItemType.olMailItem), MailItem)

            ' Add a recipient for the email
            email.Recipients.Add("recipient@address.net")

            'email.BodyFormat = OlBodyFormat.olFormatHTML

            email.HTMLBody = True

            email.Subject = "Test"
            email.Body = "This is a test <strong>email</strong><br/ >This is another line to check <i>outlook</i> email sending code"

            ' add display name, position and attach type for the attachment
            Dim DisplayName As String = "MyAttachment"
            Dim iPosition As Integer = email.Body.Length + 1
            Dim AttachType As Integer = DirectCast(OlAttachmentType.olByValue, Integer)

            'now attached the file
            'Dim Attach As Attachment = email.Attachments.Add("C:\test.txt", AttachType, iPosition, DisplayName)

            ' open to read it first
            email.Display(True)

           ' Or just send
            'email.Send()
            
        Catch
         End Try
    End Sub
End Class

Open in new window


When I preview the message, this is what it looks like, as you can see the HTML tags are ignored

This is a test <strong>email</strong><br/ >This is another line to check <i>outlook</i> email sending code
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
figured it out

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.