.NET 1.0Windows 2003.NET 1.1Windows 2000Windows XPIntermediateDevVisual StudioWindows.NETVisual BasicASP.NET
Open Default mail client in .NET






2.18/5 (33 votes)
Jan 2, 2004

160150
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