Sign in to follow this  
RipTorn

[.net] creating an email for the user to send...

Recommended Posts

I've been scratching my head on this one.. Does anyone know how I can create an email with a specified subject, body, and someone to send to. At the moment, I simply want a 'Report Error' button when something goes wrong. It creates an email, then outlook or whatever opens, and lets the user add any comments, etc and they can send it themselves. I've seen this done enough times in other applications.. I have a few other uses too.. I've tried System.Web.Mail and System.Net.Mail, but both of these are actual smtp severs... which isn't what I'm after. I've also tried a Simple MAPI wrapper from the code project, but this refused to work either.. Frankly I'm quite stuck. (It can be windows only btw so dllimport is fine) Thanks in advance.

Share this post


Link to post
Share on other sites
I belieive you can use ShellExecute to do this, in much the same way you can launch URLs in the users default browser.

mailto:name@domain.com?subject=subject%20url%20encoded&body=same%20as%20subject

Share this post


Link to post
Share on other sites
Quote:
Original post by Michalson
I belieive you can use ShellExecute to do this, in much the same way you can launch URLs in the users default browser.

mailto:name@domain.com?subject=subject%20url%20encoded&body=same%20as%20subject


There are a few flaws to this solution. First, there is a 2,083 character limitation to the URL when using ShellExecute. See KB article here. In my applications, I send a stack trace along with the user comments in the email. You will not have enough characters for for a complete trace.

Second, you do not know if the user has a mail client installed or not. Third, you may not want to give out your email address because the potential of receiving spam.

Using an SMTP service such as System.Web.Mail and System.Net.Mail will not work on most users machines because of hardware and software firewalls (especially WinXP SP 2). Also, many ISP's are blocking SMTP ports due to zombie PC's.

What I did in my application for error reporting was create a web page that my application would submit errors to via the HTTP POST command. In my case, I submit the version number, the customer's license code, the stack trace and any comments entered by the user when the submit error report screen appears. The URL I post to simply logs the information in a database and emails me with the full report using System.Net.Mail.

Advantages of this method:
1) Since you go through port 80, no firewall problems.
2) The end user doesn't need a mail client, just an internet connection.
3) Your email address is not exposed to the end user and you can send copies to other developers on your team automatically.
4) Spam is no problem since I verify the license code before recording it to a database and emailing the report.

Bob




Share this post


Link to post
Share on other sites
Thanks for both your replies.

I actually had the mailto: idea later on that night when I went to bed :) but obviously didn't try it out. I would not have thought of ShellExecute so I would probably have came to a dead end.
I've sortof been pointed in the right direction now, so what I've ended up doing is creating a temporary .eml file, then telling ShellExecute to open that. This gets around the character limit fairly well. It will do for now until I need a more robust solution.

Thanks for your help :)

r++ cyansoft, Michalson you already have my r++ :) - and thats one hell of a huge hummer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this