C#发送内置图片html格式邮件的方法
作者:令狐不聪 时间:2021-11-14 08:07:42
本文实例讲述了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#程序设计有所帮助。
标签:C#,发送,邮件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现随机验证码图片生成
2022-12-08 02:27:00
![](https://img.aspxhome.com/file/2023/1/82301_0s.jpg)
C#实现向函数传递不定参数的方法
2021-06-21 01:33:22
C#中的EventHandler观察者模式详解
2021-09-04 17:08:27
详解MyBatis逆向工程
2021-12-12 02:38:04
![](https://img.aspxhome.com/file/2023/3/64433_0s.png)
android里TextView加下划线的几种方法总结
2022-03-25 10:42:18
详解Java的Struts框架中栈值和OGNL的使用
2022-11-03 01:38:04
![](https://img.aspxhome.com/file/2023/7/71697_0s.png)
mybatis的if判断integer问题
2022-12-23 20:15:41
Android播放assets文件里视频文件相关问题分析
2021-08-10 20:04:41
使用Deflate算法对文件进行压缩与解压缩的方法详解
2022-01-27 09:48:49
Struts2配置文件中使用通配符的方法(三种形式)
2022-08-21 01:53:40
Java中的接口多继承机制
2023-08-28 06:13:48
![](https://img.aspxhome.com/file/2023/4/79824_0s.png)
详解Asp.Net MVC的Bundle捆绑
2021-09-10 05:21:38
![](https://img.aspxhome.com/file/2023/2/96322_0s.png)
Spring JPA整合QueryDSL的示例代码
2022-12-02 18:56:22
![](https://img.aspxhome.com/file/2023/1/99891_0s.png)
基于Spring的RPC通讯模型的使用与比较
2022-04-22 01:18:18
![](https://img.aspxhome.com/file/2023/5/94325_0s.png)
在IDEA使用中directory和package的操作
2022-07-05 22:05:53
![](https://img.aspxhome.com/file/2023/9/79339_0s.jpg)
详解Mybatis-plus中更新date类型数据遇到的坑
2022-08-17 21:43:14
springboot如何通过URL方式访问外部资源
2022-02-07 01:10:15
![](https://img.aspxhome.com/file/2023/7/101807_0s.png)
Mybatis generator如何自动生成代码
2023-08-13 10:15:15
![](https://img.aspxhome.com/file/2023/0/58180_0s.png)
Intellij IDEA创建spring-boot项目的图文教程
2022-06-15 01:09:59
![](https://img.aspxhome.com/file/2023/0/81920_0s.png)
详解Java中Dijkstra(迪杰斯特拉)算法的图解与实现
2023-05-03 18:35:24
![](https://img.aspxhome.com/file/2023/9/99899_0s.png)