I'm saving by capturing screenshot via that code.
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);
Then send this saved screenshot as e-mail:
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("[email protected]", "Konu");
msg.Subject = konu;
msg.IsBodyHtml = true;
msg.Body = mesaj;
msg.BodyEncoding = System.Text.Encoding.GetEncoding(1254);
NetworkCredential guvenlikKarti = new NetworkCredential("[email protected]", "*****");
client.Credentials = guvenlikKarti;
client.Port = 587;
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Send(msg);
I want to do this : How can I send a screenshot directly as e-mail via smtp protocol without saving?
To take a screenshot of your whole screen, you can press the Print Screen (or PrtSc) button on your keyboard. To automatically save your screenshot to the Pictures folder on your computer, press the Windows + Print Screen buttons at the same time. Press the Print Screen key to copy an image of your whole screen.
Using the PRINT SCREEN key Pressing PRINT SCREEN captures an image of your entire screen and copies it to the Clipboard in your computer's memory. You can then paste (CTRL+V) the image into a document, email message, or other file.
Save the Bitmap to a Stream. Then attach the Stream to your mail message. Example:
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");
Use this:
using (MemoryStream ms = new MemoryStream())
{
Ekran.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
using (Attachment att = new Attachment(ms, "attach_name"))
{
....
client.Send(msg);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With