0

Folks,
Using the System.Diagnostics.Process.Start("mailto: method of creating an email, is there a way to add a dynamic attachment (not a saved file) to the email?

I'm pretty much doing the same as this the person in this question but no-one has answered using the mailto: method. Im just wondering if its possible, and how to do it.

I've tried this but to no avail:

System.IO.MemoryStream ms = new System.IO.MemoryStream(generatedReport.DocumentBytes);
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Application.Pdf);
Attachment attachment = new Attachment(ms, ct);
attachment.ContentDisposition.FileName = "output.pdf";                            
System.Diagnostics.Process.Start("mailto:myemail &SUBJECT=Test Subject BODY=Body Text&Attachment=" + attachment);
ms.Close();

Any and all help is appreciated

Community
  • 1
  • 1
  • 1
    Unfortunately no, [the `mailto:` URL scheme does not support attachments](http://stackoverflow.com/questions/4517046/does-the-mailto-in-anchor-tag-actually-support-attachments). – Heinzi Mar 16 '15 at 15:27
  • OK thank you, back to the drawing board for me – WDalrymple Mar 16 '15 at 15:31

1 Answers1

3

In general, the mailto: URL scheme does not support attachments. Thus, you should not use it at all if you need it to work reliably with attachments.

Apparently, some mail clients still support passing Attachment=..., but they expect the ... part to be the path of a local file. Thus, in your case, you need to

  • save the file to disk (you can use a temporary file name in a temporary folder) and then
  • pass the path of the file to your mailto: link.

Note that you will have to keep the file around until the user has actually sent the mail, so you might have to think about "cleaning up" those temporary files at a later time.

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519