邮件带图片附件
var m = new MailMessage();
m.From = new MailAddress("xx");
m.To.Add(new MailAddress("xx"));
m.Attachments.Add(new Attachment(@"E:\Downloads\2.jpg"));
m.Attachments[0].ContentId = "MyPic";
m.Attachments[0].ContentDisposition.Inline = true;
m.Attachments[0].NameEncoding = m.SubjectEncoding = m.BodyEncoding = Encoding.UTF8;
//添加多个附件
m.Attachments.Add(new Attachment(@"E:\Downloads\dd.xls"));
m.Attachments[0].ContentId = "MyPics";
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(@"<img src=""{0}""/><a href=""{0}"" target=""_blank"">点击新窗口</a>", "cid:" + m.Attachments[0].ContentId);
var s = new SmtpClient();
s.EnableSsl = true;
s.Port = 587;
s.Host = "smtp.gmail.com";
s.UseDefaultCredentials = false;
s.Credentials = new System.Net.NetworkCredential("xx", "xx");
s.Send(m);