发送邮件嵌入图片
来源:互联网 发布:8051单片机图片 编辑:程序博客网 时间:2024/04/29 03:58
Introduction
Sending and receiving emails is a daily task for almost every professional, and programmers are not different. Sending emails and attachment is considered a trivial task, and all programming platforms support this feature.
Background
You can send an email with images as external links, but most email clients block external links. There is another way around to send images as part of an email.
Using the code
The following code is self explanatory. Here, we go:
- Create a string that contains the HTML message to send.
- Create an
AlternateView
object for supporting the HTML. - Create a
LinkedResource
object for the image to send. - Add a
LinkedResource
object to theAlternateView
object. - Create a
Mailmesasge
object and set itsTo
,From
, andSubject
properties. - Add an
AlternateView
object to theMailMessage
object. - Create an
SmtpClient
object and send theMailMessage
object.
Collapse | Copy Code
using System.Net.Mail;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 imageLinkedResource pic1 = new LinkedResource("pic.jpg", MediaTypeNames.Image.Jpeg);pic1.ContentId = "Pic1";avHtml.LinkedResources.Add(pic1);// Add the alternate views instead of using MailMessage.BodyMailMessage m = new MailMessage();m.AlternateViews.Add(avHtml);// Address and send the messagem.From = new MailAddress("rizwan@dotnetplayer.com", "Rizwan Qureshi");m.To.Add(new MailAddress("shayan@dotnetplayer.com", "Shayan Qureshi"));m.Subject = "A picture using alternate views";SmtpClient client = new SmtpClient("smtp.dotnetplayer.com");client.Send(m);
- 发送邮件嵌入图片
- C#发送邮件嵌入图片
- C# 发送邮件内容嵌入图片
- .NET C# 发送邮件内容嵌入图片
- .net中 发送邮件内容嵌入图片
- C# 发送邮件内容嵌入图片
- python flask发送邮件嵌入图片 Outlook
- C#邮件发送 批量发送邮件 发送邮件嵌入图片 添加附件
- 如何在ASP.NET中发送嵌入图片的邮件
- 如何在ASP.NET中发送嵌入图片的邮件
- C# 发送模板邮件并嵌入N张图片
- C# 发送模板邮件并嵌入N张图片(优化) 以模版img标签为驱动
- cdo发送图片邮件
- MailBee.NET Objects发送电子邮件(SMTP)教程五:发送带有嵌入图片的网页和HTML邮件
- 邮件正文发送图片兼容性问题
- iOS ---在app里面嵌入发送邮件功能
- spring发送带图片的邮件方法
- java发送邮件,正文图片,附件
- JS中 Math.ceil
- window.showModalDialog以及window.open用法简介
- POJ 3041 Asteroids 二分匹配
- C# 中的委托和事件
- MakeFile用法,详细到让人吐
- 发送邮件嵌入图片
- 关于dijkstra
- makefile 自动化变量
- keil MDK升级到V4.54后使用J-link问题
- 如何提高团队编程水平
- Linux多线程──生产者消费者
- 一个C++复制构造函数在不同编译器上(xcode,linux终端,VC6.0)出现结果不一致的问题
- 商战传奇:周鸿祎死磕雷军的背后的三重玄机
- LINUX系统中动态链接库的创建与使用