【发布时间】:2013-05-02 15:29:46
【问题描述】:
指定问题: 我正在创建一个位图对象,我想用电子邮件发送它。我不想先保存它或将其上传到网络服务器。只需附加它,然后将附件链接到邮件的 html 正文中。 我已经搜索了很长时间,我只能找到图片存储在文件系统或服务器上的答案。
那么有什么方法可以在不保存图像的情况下做到这一点?
谢谢
编辑: 我尝试了一段时间,终于找到了这个解决方案:
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("xxx@yyy.de"));
mail.From = new MailAddress("xxx@yyy.de");
SmtpClient sender = new SmtpClient
{
Host = "smtp.client",
Port = 25
};
mail.Subject = "test";
body= "blablabla<br><img alt=\"\" hspace=0 src=\"cid:ImagedId\" align=baseline border=0 ><br>blablabla";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
using (System.IO.MemoryStream image = new System.IO.MemoryStream())
{
Bitmap diagram = new Bitmap("C:\\qwer.bmp");
diagram.Save(image, System.Drawing.Imaging.ImageFormat.Jpeg);
LinkedResource resource = new LinkedResource(image, "image/jpeg");
resource.ContentId = "ImageId";
resource.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(resource);
mail.AlternateViews.Add(htmlView);
sender.Send(mail);
}
但是现在我的 MailClient (Lotus Notes) 没有打开邮件并出现错误:“没有 mime 数据”。 任何想法如何解决这个问题?
【问题讨论】:
-
也许this question 可以提供帮助。那里有一些很好的答案。
-
谢谢,这个问题让我走上了正轨。现在只需要解决“没有mime数据”的问题...
标签: c# html-email email-attachments