0

I'm writing an application where I have to send an email with an attachment using the default mail application.

Before the email is sent, I want the user to be able to edit the text, i.e. the application should just open the mail client with pre-filled recipient and attachment and give the user the opportunity to send it.

At very minimum I need the same effect I'd got if I selected "SendTo/Mail Recipient" from the context menu of the file.

Solutions based on the "mailto:" trick won't work as there are mail clients that do not support the "attachment=" part.

The most complete solution I've found is this one: http://www.codeproject.com/Articles/3839/SendTo-mail-recipient but it seems a lot of code for something so simple! (and also crashes when compiled with VS2008)

Is there any other option? It would be ok even if it was an external tool or script (e.g. a .vbs script to be launched with cscript).

Remo.D
  • 16,122
  • 6
  • 43
  • 74

1 Answers1

0

I would advise you to use MAPI (Messaging Application Program Interface).

If dotNet can be part of the solution, here's a ready-to-use class in C# : Class for creating MAPI Mail Messages. It would give you something like this:

MapiMailMessage message = new MapiMailMessage("Test Message", "Test Body");
message.Recipients.Add("Test@Test.com");
message.Files.Add(@"C:\del.txt");
message.ShowDialog();

Otherwise, you can always do it in C++ if you feel confortable with it, like this answer suggest.

Then, you will be able to ShellExecute the binary executable and pass it some parameters.

Hope this helps :-)

Community
  • 1
  • 1
Frederik.L
  • 5,522
  • 2
  • 29
  • 41