当前位置: 编程技术>.net/c#/asp.net
.net中 发送邮件内容嵌入图片的具体实例
来源: 互联网 发布时间:2014-08-25
本文导语: 例程一 邮件内容调用图片格式为: 发送邮件的服务端代码为: SmtpClient 发送邮件的对象 //代码省略 代码如下:System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();mailMessage.From="发送者邮箱";mailMessage.To.Add("收件人邮件列表...
例程一
邮件内容调用图片格式为:
发送邮件的服务端代码为:
SmtpClient 发送邮件的对象 //代码省略
代码如下:
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From="发送者邮箱";
mailMessage.To.Add("收件人邮件列表");
mailMessage.CC.Add("抄送人邮件列表");
mailMessage.Subject = subject;
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(content,null,"text/html");
LinkedResource lrImage = new LinkedResource("a.jpg","image/gif");
lrImage.ContentId = "Email001";
htmlBody.LinkedResources.Add(lrImage);
mailMessage.AlternateViews.Add(htmlBody);
SmtpClient.Send(mailMessage);
例程二
代码如下:
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "smtp.163.com";
smtp.Credentials = new NetworkCredential("renzhijie1111", "**");
MailMessage mm = new MailMessage();
mm.From = new MailAddress("renzhijie1111@163.com", "无敌任志杰测试");
mm.To.Add("renzhijie1990@vip.qq.com");
mm.Subject = "发送带图片邮件";
string plainTextBody = "如果你邮件客户端不支持HTML格式,或者你切换到“普通文本”视图,将看到此内容";
mm.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plainTextBody, null, "text/plain"));
////HTML格式邮件的内容
string htmlBodyContent = "如果你的看到这个, 说明你是在以 HTML 格式查看邮件
";
htmlBodyContent += "