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