Programatically create formatted / rich text to send in an email

Posted on 2008-11-16
Last Modified: 2012-05-05
I need  to send formatted text (bullet points, bolded words etc...)  in an email from our app.  I must also fill in some of the information from the database.   Such as names, order details etc..  

The code snippet details how I am sending the email which works.

How can I send this in the body of the email with all the formatting they requested?




Dim StringCommand As New System.Text.StringBuilder




        If Subject <> "" Then

            StringCommand.Append("subject=" & Subject & "&")

        End If

        If CC <> "" Then

            StringCommand.Append("cc=" & CC & "&")

        End If

        If BCC <> "" Then

            StringCommand.Append("bcc=" & BCC & "&")

        End If

        If Body <> "" Then

            StringCommand.Append("body=" & Body & "&")

        End If



Open in new window

Question by:KimberleyY
    LVL 10

    Accepted Solution

    Hi KimberleyY.

    You should look at using objects in the System.Net.Mail namespace in order to get HTML sent. Have a look at the example code.

    Hope this helps.
    Imports System.Net.Mail 
    Public Class MyEmail 
        Public Sub SendEmail()
            Dim msg As New MailMessage
            Dim smtpServer As New SmtpClient 
            smtpServer.Port = 25
            smtpServer.Host = "nameofemailserver"
            smtpServer.Credentials = New Net.NetworkCredential("username", "password") 
            msg.Body = "<h1>Test</h1>"
            msg.IsBodyHtml = True 
        End Sub
    End Class

    Open in new window


    Author Comment

    Hi MrClyfar,

    Thanks!  I was afradi that the message needed to be in HTML.  I did find some free converters for rtf to html.  And I will also look into the System.Net.Mail namespace.

    Thanks Again

    Author Closing Comment

    Good Job

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now