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

 时间:2026-04-29 04:38:25

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、完成发送邮件。

  • 如何使用SMTP进行发送邮件
  • 发送邮件如何添加附件
  • php使用smtp怎么发送邮件
  • 发送邮件要注意什么事项 邮件礼仪
  • 阿里邮箱smtp设置
  • 热门搜索
    焦虑症怎么治疗 c盘满了怎么办 作者简介怎么写 夜间模式怎么开 猕猴桃怎么保存 小孩口腔溃疡怎么办 肌肉腿怎么瘦 shirt怎么读 退休金怎么算 血压低头晕怎么办最快最有效