Solved

Send email via VB.net in HTML form?

Posted on 2008-10-12
6
1,725 Views
Last Modified: 2012-05-05
Hi,

I have setup a form to send emails via Outlook and the emails are sent containing just text.

However, I want to send these emails containing HTML. Can anyone show me how I can set the below code to send the emails in HTML form?

Thanks,
Paul
Public Class Form1
 

    Dim OutApp As Object

    Dim OutMail As Object

    Dim strbody As String
 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        OutApp = CreateObject("Outlook.Application")

        OutApp.Session.Logon()

        OutMail = OutApp.CreateItem(0)
 

        strbody = "<html><body><font color='red'>TEXT</font></b></body></html>" & _

                  "Dear all," & vbNewLine & vbNewLine & _

                  "This is a test email." & vbNewLine & _

                  "" & vbNewLine & _

                  "" & vbNewLine & _

                  "Thanks and regards," & _

                  "" & vbNewLine & _

                  "Paul"

    End Sub
 

    Private Sub SendClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendClose.Click

        Dim DestinationEmail As String

        Dim RequestNumber As String
 

        RequestNumber = RequestNo.Text

        DestinationEmail = SendTo.Text
 

        With OutMail

            .To = DestinationEmail

            .CC = ""

            .BCC = ""

            .Subject = "DWP Service Desk - 4 DAY CLOSE - <" & RequestNumber & "> - chkd"

            .Body = strbody

            .send()
 

            MessageBox.Show("Email Sent!")
 

            'Clear Text Boxes

            SendTo.Text = ""

            RequestNo.Text = ""

            LocationCode.Text = ""

            Subject.Text = ""

        End With
 
 

    End Sub

End Class

Open in new window

0
Comment
Question by:m0tSiE
6 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22697429
Try this

With OutMail
            .To = DestinationEmail
            .CC = ""
            .BCC = ""
            .Subject = "DWP Service Desk - 4 DAY CLOSE - <" & RequestNumber & "> - chkd"
            .Body = strbody
            .htmlbody = strbody
            .send()With OutMail
            .To = DestinationEmail
            .CC = ""
            .BCC = ""
            .Subject = "DWP Service Desk - 4 DAY CLOSE - <" & RequestNumber & "> - chkd"
            .htmlbody = strbody
            .send()
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22697456
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 22697466
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:elimesika
ID: 22697555
0
 

Author Closing Comment

by:m0tSiE
ID: 31505440
Thanks, worked great! :D
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22697896
You are welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

19 Experts available now in Live!

Get 1:1 Help Now