C# 使用SMTP 发送邮件时如何邮件内容中显示图片

时间:2026-02-16 09:36:45

1、初始化 MailMessage

MailMessage email = new MailMessage();

2、添加附件

email.Attachments.Add(newAttachment("C:\\img\\ewen.gif"));

3、设置附件类型

email.Attachments[0].ContentType.Name= "image/gif" ;

4、设置附件 Id

email.Attachments[0].ContentId = "ewen";

5、设置附件为 inline-内联

email.Attachments[0].ContentDisposition.Inline= true;

6、设置附件的编码格式

email.Attachments[0].TransferEncoding =System.Net.Mime.TransferEncoding.Base64;

7、在HTML邮件正文中用img 标签引用图片,src 设置为 cid:附件Id

stringmailBody = "这里显示图片:<br><img alt='图片' src=cid:ewen>";

8、完成发送邮件。

© 2026 途途旅游
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com