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:test@example.invalid?subject=mysubject&body=mymessage". Do you have any examples on this?
4 Answers
Try this:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mailto:someone@somewhere.com?subject=hello&body=love my body";
proc.Start();

- 53,046
- 9
- 139
- 151
-
This solution still doesn't handle the long body text previously mentioned. – acaruci May 08 '17 at 16:17
-
1What if I need to include attachment? How to do it? – Rich Jul 18 '17 at 10:45
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("person1@somewhere.com");
mapi.AddRecipientTo("person2@somewhere.com");
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");

- 755
- 1
- 7
- 12
-
-
-
This doesn't work for me anymore, after migrating to Outlook 2016 – Stealth Rabbi Apr 09 '18 at 19:27
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.

- 42,236
- 12
- 79
- 110
-
1That is a good article. Anyone considering MAPI should be aware of the problems they _might_ end up running into before they take the plunge. – chessofnerd Jul 03 '13 at 18:44
-
1@chessofnerd what problems might those be? Can you go into a bit more detail? – Elkvis Jul 06 '17 at 13:31
-
This is what I tried:
Process.Start("mailto:demo@example.invalid?subject=" +
HttpUtility.HtmlAttributeEncode("Application error report") +
"&body=" + HttpUtility.HtmlAttributeEncode(memoEdit1.Text));
But if the body text is too large I get the exception:
Win32Exception "The data area passed to a system call is too small"
So the question is still open since I need to handle long body text. I don't know the size limit for this error.

- 7,805
- 15
- 59
- 92