How to send email using default email client?
I want to send an email from a .net windows forms application using the system's default email client (thunderbird, outlook, etc.). I'd like to preset the subject and body text -- I think there's a way to do this by sending something like this to windows explorer: "mailto:[email protected]?subject=mysubject&body=mymessage". Do you have any examples on this?
Solution 1:
Try this:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mailto:[email protected]?subject=hello&body=love my body";
proc.Start();
Solution 2:
If you are working in a MS Windows environment only then you can use MAPI32.DLL. A managed wrapper can be found here:
http://www.codeproject.com/KB/IP/SendFileToNET.aspx
Code looks like this:
MAPI mapi = new MAPI();
mapi.AddAttachment("c:\\temp\\file1.txt");
mapi.AddAttachment("c:\\temp\\file2.txt");
mapi.AddRecipientTo("[email protected]");
mapi.AddRecipientTo("[email protected]");
mapi.SendMailPopup("testing", "body text");
// Or if you want try and do a direct send without displaying the mail dialog
// mapi.SendMailDirect("testing", "body text");
Solution 3:
The correct way to do this is by using MAPI, but using interop code to the MAPI dll is not actually a supported nor recommended way to do this. I have done this and, as long as you are very careful about your interop code and don't do much more interaction than opening the mail client to send an email you should be OK.
There are several problems with using the "mailto" approach, least of which is that you can't attach files.