C# Attaching System.Drawing.Image to Email

后端 未结 2 1859
夕颜
夕颜 2021-01-17 22:30

Is there any way to attach System.Drawing.Image to email with out saving it, then grabbing it from the saved path.

Right now I\'m creating the image and saving it. I

2条回答
  •  渐次进展
    2021-01-17 23:05

    You can't pass an Image directly to an attachment, but you can skip the file system by just saving the image to a MemoryStream, and then providing that MemoryStream to the attachment constructor:

    var stream = new MemoryStream();
    image.Save(stream, ImageFormat.Jpeg);
    stream.Position = 0;
    
    mail.Attachments.Add(new Attachment(stream, "image/jpg"));
    

提交回复
热议问题