C#发送邮件并将图片插入邮件内容
2021-08-05 20:56
标签:邮件内插入图片 邮件内容的字符串StringBuilder Mbody = new StringBuilder(); Mbody.AppendLine("尊敬的领导:"); Mbody.AppendLine(""); Mbody.AppendLine(" 您好!"); Mbody.AppendLine("" + mail.MailBoby + ""); int id = 0; foreach (Models.ChartInfoModel item in mail.ChartList) { Mbody.AppendLine("" + ""); Mbody.AppendLine(" "); 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/1964248C#发送邮件并将图片插入邮件内容标签:邮件内插入图片原文地址:http://317057112.blog.51cto.com/1361376/1964248