Programatically create formatted / rich text to send in an email

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason EvansSenior Software DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KimberleyYAuthor Commented:
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
KimberleyYAuthor Commented:
Good Job
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.