如何采取截图并通过电子邮件发送programaticly上的dotnet截图、电子邮件、dotnet、programaticly

2023-09-04 00:27:55 作者:过骗

背景:

我正在开发一个经营业务的应用程序,并在最后阶段,我们遇到了一些交流中心的错误,大多用的连接和一些边缘用例。

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.

问题:

我想提供一个更好的体验,并在同一个对话框提供了一个按钮,至极uppon单击,会打开Outlook和prepare电子邮件,用截屏作为附件,也许一个日志文件,则用户可以添加备注和preSS发送键。

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.

问:

我怎么能借此截图programaticly,然后将其添加为附件的Outlook邮件?

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

注:

该应用程序是Microsoft .NET框架2.0,C#或VB

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

推荐答案

首先,发送截图,您可以使用下面的code:

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);

要通过outlook发送邮件,你可以使用的方法描述这里

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