c# - 通过 C# 发送屏幕截图

标签 c# smtp

我通过该代码捕获屏幕截图来保存。

Graphics Grf;
Bitmap Ekran = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppPArgb);
Grf = Graphics.FromImage(Ekran);
Grf.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
Ekran.Save("screen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

然后将保存的屏幕截图作为电子邮件发送:

SmtpClient client = new SmtpClient();
MailMessage msg = new MailMessage();
msg.To.Add(kime);
if (dosya != null)
{
   Attachment eklenecekdosya = new Attachment(dosya);
   msg.Attachments.Add(eklenecekdosya);
}
msg.From = new MailAddress("aaaaa@xxxx.com", "Konu");
msg.Subject = konu;
msg.IsBodyHtml = true;
msg.Body = mesaj;
msg.BodyEncoding = System.Text.Encoding.GetEncoding(1254);
NetworkCredential guvenlikKarti = new  NetworkCredential("bbbb@bbbb.com", "*****");
client.Credentials = guvenlikKarti;
client.Port = 587;
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Send(msg); 

我想这样做:如何在不保存的情况下通过 smtp 协议(protocol)将屏幕截图直接作为电子邮件发送?

最佳答案

将位图保存到流中。然后将 Stream 附加到您的邮件消息中。示例:

System.IO.Stream stream = new System.IO.MemoryStream();
Ekran.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
// later:
Attachment attach = new Attachment(stream, "MyImage.jpg");

关于c# - 通过 C# 发送屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7529968/

相关文章:

php - 如何在 php smtp 中发送带有阿拉伯语 html 内容的电子邮件

c# - 来自 ASP.NET MVC 应用程序 : database, 队列文件夹的 SMTP 邮件还是异步?

C# 从外部 dll 读取 web.config 中的 <system.net><mailSettings>

smtp - Powershell 脚本在 Powershell 中有效,但在任务计划程序中失败

c# - 下载 zip 文件 ASP MVC 时出现问题

php - 从 Zend Framework 应用程序向数百个收件人发送电子邮件的最佳方法是什么?

c# - 回发后丢失 session

C#如何使用两个参数设置属性

c# - C# 信号量中的 Release 和 WaitOne

c# - Prism View 定位器 : How to fix "Your views must implement IView"