staticvoidSendMail()
{
varm=newMailMessage();
m.From=newMailAddress("youjb@xxx.com.cn");
m.To.Add(newMailAddress("youjb@xxx.com.cn"));
m.Attachments.Add(newAttachment(@"C:\Users\greystar\Desktop\江阴\IMG_1463.JPG"));
m.Attachments[0].ContentId="MyPic";
m.Attachments[0].ContentDisposition.Inline=true;
m.Attachments[0].NameEncoding=m.SubjectEncoding=m.BodyEncoding=Encoding.UTF8;
m.Subject="测试邮件";
m.IsBodyHtml=true;
m.Body=string.Format(@"<imgsrc=""{0}""/><ahref=""{0}""tartget=""_bland"">点击在新窗口打开图片</a>","cid:"+m.Attachments[0].ContentId);
vars=newSmtpClient();
s.Port=25;
s.Host="mail.xxx.com.cn";
s.Credentials=newSystem.Net.NetworkCredential("youjb@xxx.com.cn","mypwd");
try
{
s.Send(m);
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
}
}
一段发送邮件的代码(内嵌图片)
最新推荐文章于 2021-06-04 19:11:36 发布
本文介绍如何使用C#编程语言通过SMTP服务发送带有内联图片附件的电子邮件。具体实现包括设置邮件内容为HTML格式,并将图片作为邮件的一部分直接显示在邮件正文中。
4377

被折叠的 条评论
为什么被折叠?



