当前位置: 移动技术网 > IT编程>开发语言>c# > C#发送内置图片html格式邮件的方法

C#发送内置图片html格式邮件的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例讲述了c#发送内置图片html格式邮件的方法。分享给大家供大家参考。具体如下: 下面的代码用于发送html格式的邮件,并且可以将图片附加到邮件一起发出

本文实例讲述了c#发送内置图片html格式邮件的方法。分享给大家供大家参考。具体如下:

下面的代码用于发送html格式的邮件,并且可以将图片附加到邮件一起发出

mailmessage m = new mailmessage();
m.from = new mailaddress("ir@jb51.net", "raja item");
m.to.add(new mailaddress("su@jb51.net", "sekaran uma"));
m.subject = "html email with embedded image coming!";
// create the html message body
// reference embedded images using the content id
string htmlbody = "<html><body><h1>picture</h1><br><img src=\"cid:pic1\"></body></html>";
alternateview avhtml = alternateview.createalternateviewfromstring
  (htmlbody, null, mediatypenames.text.html);
// create a linkedresource object for each embedded image
linkedresource pic1 = new linkedresource("pic.jpg", mediatypenames.image.jpeg);
pic1.contentid = "pic1";
avhtml.linkedresources.add(pic1);
// create an alternate view for unsupported clients
string textbody = "you must use an e-mail client that supports html messages";
alternateview avtext = alternateview.createalternateviewfromstring
  (textbody, null, mediatypenames.text.plain);
m.alternateviews.add(avhtml);
m.alternateviews.add(avtext);
// send the message
smtpclient client = new smtpclient("smtp.jb51.net");
client.send(m);

希望本文所述对大家的c#程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网