Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Email message in .NET

I want to be able to create an email message with an attachment, but not send it. The email should open in Outlook where the user can send himself.

I have been playing around with Mailto: command in order to open a new mail message, however, Outlook client doesn't seem to support adding attachments using the Mailto: command.

I do not want to use COM to do this.

Does anyone know of a way to achieve this? I think it might not be possible without COM.

like image 789
jgallant Avatar asked Oct 18 '25 15:10

jgallant


2 Answers

If you want to open the mail message in Outlook, then I'm pretty sure you will need to use COM. Is there any particular reason you want to interact with Outlook rather than automate the sending using SMTP and the System.Net.Mail namespace?

Edit: It seems you can specify an attachment using a mailto link, by the way. Example:

mailto:[email protected]?subject=foo&body=bar&attachment="C:/foo/bar.txt"

Have you tried this with Outlook? However, I would still recommend COM as the way to go, since it gives you a good deal more control over what you can do with Outlook and mail messages.

like image 115
Noldorin Avatar answered Oct 21 '25 05:10

Noldorin


The only way around COM (or VSTO) I can think of would be to use the command line options of Outlook. Using Process.Start you could start Outlook with the options described in this answer (by VonC):

Open a new mail message:

    outlook.exe /c ipm.note

Open a new mail message and populate sender:

    outlook.exe /c ipm.note /m [email protected]

Open a new mail message with attachment:

    outlook.exe /c ipm.note /a filename

Combination:

    outlook.exe /c ipm.note /m [email protected]&subject=test%20subject&body=test%20body

You can retrieve the installation folder of Outlook from the following Registry keys:

Outlook 2007:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Outlook\InstallRoot

Outlook 2003:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Outlook\InstallRoot

Outlook XP:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Outlook\InstallRoot
like image 35
Dirk Vollmar Avatar answered Oct 21 '25 06:10

Dirk Vollmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!