我试图通过System.Net.Mail.SmtpClient发送内嵌图像。发送时,图像会丢失其内容ID,并且无法在HTML正文中引用。在谷歌上搜索这个问题什么都没有,所以我做错了什么?
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
string contID = "Image@image.img";
Attachment attach = new Attachment("c:/image.png");
mail.Attachments.Add(attach);
attach.ContentDisposition.Inline = true;
attach.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
attach.ContentId = contID;
mail.Body = "<htm><body><img src=3D\"cid:" + contID + "\"></body></html>";
mail.From = new MailAddress("from@doma.in");
mail.To.Add("to@doma.in");
mail.Subject = "Test";
smtpC.Send(mail);
这是在电子邮件中发送的附件
----boundary_0_4a1cf86c-c96f-4498-a5a5-7b3e9b49357d
content-type: image/png; name="image.png"
content-transfer-encoding: base64
content-disposition: inline; filename=image.png
[base64 data here]