首页 > Windows开发 > 详细

C#发送邮件并将图片插入邮件内容

时间:2017-09-11 17:40:40      阅读:205      评论:0      收藏:0      [点我收藏+]

 

邮件内容的字符串

StringBuilder Mbody = new StringBuilder();            Mbody.AppendLine("尊敬的领导:");            Mbody.AppendLine("</br>");            Mbody.AppendLine("<p>    您好!</p>");            Mbody.AppendLine("<p>" + mail.MailBoby + "</p>");            int id = 0;            foreach (Models.ChartInfoModel item in mail.ChartList)            {                Mbody.AppendLine("" + "<a href=" + "‘http://10.18.100.77‘><img alt=‘图片‘ src=cid:" + id + "></a>");                Mbody.AppendLine(" <hr />");                id++;            }
///////////////////////////////////
    int j = 0;            foreach (Models.ChartInfoModel item in mail.ChartList)            {
                string filePath = Path.Combine(item.ChartPath, item.ChartTitle + ".png");                message.Attachments.Add(new Attachment(filePath));                //设置附件类型                message.Attachments[j].ContentType.Name = "image/png";                //设置附件 Id                message.Attachments[j].ContentId = j.ToString();                //设置附件为 inline-内联                message.Attachments[j].ContentDisposition.Inline = true;                //设置附件的编码格式                message.Attachments[j].TransferEncoding = System.Net.Mime.TransferEncoding.Base64;                j++;            }


本文出自 “温馨梦痕” 博客,请务必保留此出处http://317057112.blog.51cto.com/1361376/1964248

C#发送邮件并将图片插入邮件内容

原文:http://317057112.blog.51cto.com/1361376/1964248

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!