Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Open Default mail client in .NET

0.00/5 (No votes)
1 Jan 2004 1  
hi i wanted to write an application where i could open my browsers default mail client, i was unable to find any thing in .NET hence this code.. enjoy

Introduction


I was writing an emailing application in VB.NET when I came across a situation where I needed to load the default email client of the user's machine with all the email fields filled up.  I was not able to find a suitable solution for this on the Internet hence I thought why not write one.  It is easy to understand.  For comments please mail me at Melroy_Britto@Hotmail.com

 

Building The Message

public class OpenDefaultClient
Function openclient()
'string builder used for concatination
Dim MsgBuilder As New System.Text.StringBuilder
MsgBuilder.Append("mailto:melroy@testmail.com")
MsgBuilder.Append("&cc=testcc@testcc.com,testcc1@testcc.com")
MsgBuilder.Append("&bcc=testcc@testbcc.com,testcc1@testbcc.com")
MsgBuilder.Append("&subject=this is test subject")
MsgBuilder.Append("&body=this is test body")
MsgBuilder.Append("&Attach="c:\mailattach.txt")
'Debug.WriteLine(MsgBuilder.ToString)
ExecuteFile(MsgBuilder.ToString)
End Function 

Starting The Default Email Client

Private Function ExecuteFile(ByVal FileName As String) As Boolean
Dim myProcess As New Process
myProcess.StartInfo.FileName = FileName
myProcess.StartInfo.UseShellExecute = True
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.Start()
myProcess.Dispose()
End Function
End 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here