views:

358

answers:

5

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.

+5  A: 

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.

Noldorin
Yes. In order to send via SMTP with my current employer, I need to make a SMTP relay request to gain access.I was hoping to allow users to send the email themselves, since they already have the credentials.
Jon
@Jon: Fair enough. I would recommend COM as the way to interface with Outlook then. It isn't terribly hard to do, and there should be enough examples around (on MSDN for example).
Noldorin
Specifying an attachment via mailto does not work with Outlook 2007 afaik.
0xA3
Sorry Noldorin, had to accept another answer, as it worked for what I was looking for.
Jon
@Jon: No worries. I think you've gone for the slightly uglier solution, but whatever works for you is good! :)
Noldorin
It is quite ugly, but I needed to stay away from adding new references for the time being.
Jon
+1  A: 

You've answered yourself there - you can either do it through COM (via the primary interop assemblies), or you can send via SMTP directly (which would not touch the user's email client at all)

Rowland Shaw
A: 

I'm not sure if you can link it into Outlook (I'm guessing you'll have to use MAPI), but System.Net.Mail is great.

chills42
+2  A: 

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
0xA3
This is exactly what I was looking for.outlook.exe /c ipm.note /a filename works perfectly.Thanks!
Jon
A: 

you can also save the message to folder instead sending only by configuring smtp settings

<system.net>
<mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="c:\pickup-smtp\"/>        
  </smtp>
</mailSettings>

Jan Remunda