.net – How to take a screenshot and send by email programaticly on dotnet

.net.net-2.0attachmentoutlookscreenshot

Background:

I'm developing a bussiness application, and in the final stages we are encountering some extrange errors, mostly with connection and some edge use cases.

For this kind of exceptions, we now provide a nice dialog with error details, of which the user take a screenshot, and send by email with some remarks.

Problem:

I would like to provide a better experience, and provide a single button in the same dialog, wich uppon click, would open outlook and prepare the email, with a screenshot as attachment and maybe a log file, then the user can add remarks and press the send button.

Question:

How can I take this screenshot programaticly, and then add it as attachment in a outlook mail?

Remarks:

The app is in Microsoft .Net Framework 2.0, C# or VB

Best Solution

First of all, to send the screenshot, you can use the following code:

//Will contain screenshot
Bitmap screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
Graphics screenshotGraphics = Graphics.FromImage(bmpScreenshot);
//Make the screenshot
screenshotGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
screenshot.save("a place to temporarily save the file", ImageFormat.Png);

To send the mail through outlook, you could use the method described here

Related Question