tags:

views:

421

answers:

6

I'm working on a Windows Forms (.NET 3.5) application that has a built-in exception handler to catch any (heaven forbid) exceptions that may arrise. I'd like the exception handler to be able to prompt the user to click a "Send Error Report" button, which would then cause the app to send an email to my FogBugz email address.

What's the best way to do this, and are there any "gotchas" to watch out for?

+2  A: 

You'll want to use the SmtpClient class as outlined here.
There are no gotchas - sending email is about as easy as it gets.

Esteban Araya
How scalable is it if you need to send mail to 1000 of your users with smtp? Do you have to write extra code to slow down so the smtp server would not be flooded?
Haoest
+1  A: 

You might also want to check out the 3rd party aspNetEmail library, which has a lot of useful features to offer above what System.Net.Mail gives you.

Eric Z Beard
+1  A: 

In a controlled environment, using SmtpClient would be the answer. But on a user's machine you would need an SMTP server to send through.

You could prompt the user for their SMTP credentials, but I think that would be impractical for your case. As a user, I would not want to provide my SMTP credentials to a random app (think SPAM). You also don't want to hard-code your own SMTP credentials into the app, it would be trivial for a malicious user to sniff those credentials and use your server to send SPAM.

Ideally you would be able to use the user's mail agent to send the email. I was thinking you might be able to formulate and execute a mailto: URL, but I'm not sure if you'd be able to specify the body or any attachments for the message.

Brannon
rpetrich
+5  A: 

You shouldn't need to worry about client credentials and just use the SmtpClient as suggested by Esteban. You will need the user to provide a valid Smtp server url at configuration, but most ISPs allow anonymous smtp providing you are on their network (one of their clients) - as long as the user puts in the url for their ISPs smptp server then most people wouldn't have any problems.

Note: There is a predefined section of the .config file for storing the configuration options for the SmtpClient object. If you put the settings in there you don't have to explicitly set anything in you code when sending an email. An example of the section is below:

<system.net>
   <mailSettings>
      <smtp deliveryMethod="Network" from="[email protected]">
         <network host="smtp.somewhere.com.au" />
      </smtp>
   </mailSettings>
</system.net>

The user name and password are optional. Intellisense works for these parts of the config file.

Edit: slight correction to my code example.

Dr8k
Hey! Would you please spell my name correctly? Thanks, Esteban
Esteban Araya
+2  A: 

You mentioned you're using Fogbugz.

Try http://www.fogcreek.com/FogBugz/docs/60/topics/customers/BugzScout.html?isl=59722 or http://www.fogcreek.com/FogBugz/blog/post/C-wrapper-for-the-FogBugz-API.aspx?isl=59722

There is some sample code around, I think in your FB install directory. I checked with Michael Pryor re: licensing and he said it was fine to use their code, but YMMV, so I'd check.

It provides a good starting point.

Byron Ross
A: 

You'll want to use the SmtpClient class as outlined here. There are no gotchas - sending email is about as easy as it gets.

An extensive System.Net.Mail FAQ is located here.

Robbo