tags:

views:

55

answers:

2

My C# application needs to email problem reports from the user's machine to a support tech. There is no common SMTP server available, so I don't think I can use System.Net.Mail; instead the message must be sent using the user's own email program and account. I could use office automation to launch outlook and compose a message. But what if the user is not using outlook? Is there any more general mechanism that is supported by multiple email clients? Or is there a library that knows how to detect and invoke various clients?

EDIT: as this for submitting problem reports, I need to include attachments or (at worst) a long message body...

+8  A: 
Process.Start("mailto:[email protected]");

The Process.Start method hands off to the operating system the responsibility of executing a particular instruction. Windows will recognize the mailto scheme and lauch the appropriate mail client. This is configured using Default Programs.

Will
But what about composing the message?
Eric
@Eric: See my answer... The body is problematic, but subject, cc, and bcc are pretty easy.
Reed Copsey
@eric The `mailto` scheme is a standard URI and has a number of different query/fragment parts that you can use to configure the email. Check out the RFC for more info: http://tools.ietf.org/html/rfc2368
Will
@eric also if you have more specific requirements (like automatically sending the email--a bad requirement imho) you'll have to use automation for the particular email client. That's a bit more heavy lifting than Process.Start can handle.
Will
+4  A: 

If you want this to work with any email applications, you probably need to just use Process.Start with a mailto: URL defined with a short body and subject.

This should work, in a general purpose case:

Process.Start(@"mailto:[email protected][email protected]&[email protected]&subject=Bug Report&body=This may or may not show up.");

However, the body tag is often ignored by mail clients. Unfortunately, there is no general purpose way to get everything in a mailto: .

Reed Copsey