一段发送邮件的代码(内嵌图片)

staticvoidSendMail()
{
varm=newMailMessage();
m.From=newMailAddress("[email protected]");
m.To.Add(newMailAddress("[email protected]"));
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("[email protected]","mypwd");
try
{
s.Send(m);
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
}
}

你可能感兴趣的:(C++,c,.net,C#)