Solved

Send email via VB.net in HTML form?

Posted on 2008-10-12
6
1,718 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

12 Experts available now in Live!

Get 1:1 Help Now