Click here to Skip to main content
15,867,939 members
Articles / Web Development / ASP.NET
Article

Open Default mail client in .NET

Rate me:
Please Sign up or sign in to vote.
2.18/5 (33 votes)
1 Jan 2004 158K   28   22
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("<A href="mailto:melroy@testmail.com">mailto:melroy@testmail.com</A>")
MsgBuilder.Append("<A href="mailto:&cc=testcc@testcc.com,testcc1@testcc.com">&cc=testcc@testcc.com,testcc1@testcc.com</A>")
MsgBuilder.Append("<A href="mailto:&bcc=testcc@testbcc.com,testcc1@testbcc.com">&bcc=testcc@testbcc.com,testcc1@testbcc.com</A>")
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


Written By
Web Developer
India India
hi i lovvvvvvvvvvvvvvvvvvvveeeeeeeeeeeee CodeProject Wink | ;)

Comments and Discussions

 
QuestionWhy is this voted so low? Pin
asdqwewqe22-Jan-09 3:54
asdqwewqe22-Jan-09 3:54 
GeneralMy vote of 2 Pin
mahi_198818-Dec-08 2:02
mahi_198818-Dec-08 2:02 
GeneralHo to develop Same application in ASP.NEt [modified] Pin
mrMdpendable3-Jul-08 17:57
mrMdpendable3-Jul-08 17:57 
GeneralNot working with ASP.Net and c# as code behind Pin
shdeo18-Jul-07 1:22
shdeo18-Jul-07 1:22 
QuestionAttachment doesn't work for me Pin
Timan Zhao28-Jun-07 21:34
Timan Zhao28-Jun-07 21:34 
AnswerRe: Attachment doesn't work for me Pin
Timan Zhao28-Jun-07 22:34
Timan Zhao28-Jun-07 22:34 
GeneralLength restriction Pin
zespri1-Mar-06 17:22
zespri1-Mar-06 17:22 
GeneralRe: Length restriction Pin
leggan22-Apr-08 5:27
leggan22-Apr-08 5:27 
Anyone found a solution for this limitation?
Question&body problem Pin
Rob 1234523-Feb-06 1:19
Rob 1234523-Feb-06 1:19 
AnswerRe: &body problem Pin
Rob 1234524-Feb-06 18:21
Rob 1234524-Feb-06 18:21 
GeneralRe: &body problem Pin
clu826-Nov-08 2:54
clu826-Nov-08 2:54 
GeneralAttachment Pin
Srinivasan Raju1-Sep-05 2:12
Srinivasan Raju1-Sep-05 2:12 
GeneralRe: Attachment Pin
MDT Daniel19-Sep-06 21:04
MDT Daniel19-Sep-06 21:04 
GeneralAttachment is working !!!!! Pin
Martin Wolff22-Feb-05 2:01
sussMartin Wolff22-Feb-05 2:01 
GeneralRe: Attachment is working !!!!! Pin
Anonymous6-Apr-05 4:28
Anonymous6-Apr-05 4:28 
GeneralRe: Attachment is working !!!!! Pin
Anonymous10-Jul-05 14:39
Anonymous10-Jul-05 14:39 
GeneralRe: Attachment is working !!!!! Pin
fferdinanvi22-Jul-05 14:24
fferdinanvi22-Jul-05 14:24 
GeneralRe: Attachment is working !!!!! Pin
rohit.dhamija19-Sep-05 19:05
rohit.dhamija19-Sep-05 19:05 
GeneralRe: Attachment is working !!!!! Pin
silkkeng26-Sep-05 14:46
silkkeng26-Sep-05 14:46 
GeneralSimply the attachments cannot work! Pin
Janko Mrkvicka19-Nov-04 3:17
Janko Mrkvicka19-Nov-04 3:17 
GeneralRe: Simply the attachments cannot work! Pin
tej5107826-May-05 18:38
tej5107826-May-05 18:38 
Generalopen default mail client Pin
manojkumarsn10-Sep-04 23:23
manojkumarsn10-Sep-04 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.