Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse Internet Explorer to start sending email in Visual Basic .NET
DescriptionThis example shows how to use Internet Explorer to start sending email in Visual Basic .NET.
Keywordsemail, mail, Internet Explorer, IExplore, VB.NET
CategoriesOffice, Software Engineering
 
The code composes a mailto command as in (all on one line):

    mailto:me@nowhere.com?Subject=You must buy these books!
    &Body=Prototyping with Visual Basic%0D%0AVisual Basic G
    raphics Programming%0D%0AReady-to-Run Visual Basic Algo
    rithms%0D%0A

The HttpUtility.HtmlEncode method converts a string into an HTML-encoded string, replacing special characters with hex values and so forth.

Next the program makes a ProcessStartInfo object specifying IExplore.exe as the program to start and the mailto command text as an argument for the program. Finally it uses Process.Start to start IExplore.

 
' Compose the command string.
Dim txt As String = ""
If txtCc.Text.Length > 0 Then txt &= "&cc=" & txtCc.Text
If txtBcc.Text.Length > 0 Then txt &= "&bcc=" & txtBcc.Text
txt &= "&subject=" & HttpUtility.HtmlEncode(txtSubject.Text)
txt &= "&body=" & HttpUtility.HtmlEncode(txtBody.Text)

' Remove the initial &.
If txt.Length > 0 Then txt = txt.Substring(1)

' Add the To addresses.
txt = "mailto:" & txtTo.Text & "?" & txt

' Start the default mail system.
Dim start_info As New ProcessStartInfo("IExplore.exe")
start_info.WindowStyle = ProcessWindowStyle.Maximized
start_info.Arguments = txt
System.Diagnostics.Process.Start(start_info)
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated