ASP.NET中使用System.Net.Mail发邮件
2012-11-15 16:04:30 来源:WEB开发网MailAddress copy = new MailAddress("mailto:CopyToEmail@website.com");
message.CC.Add(copy);
SmtpClient client = new SmtpClient("SMTP Server");
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
}
四、邮件为HTML,而且带图片
public static void SendMail()//带HTML,并且HTML中有图片的邮件发送
{
MailAddress from = new MailAddress("FromEmail@website.com");
MailAddress to = new MailAddress("ToEmail@website.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "邮件标题";
string plainTextBody = "如果你邮件客户端不支持HTML格式,或者你切换到“普通文本”视图,将看到此内容";
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plainTextBody, null, "text/plain"));
string htmlBodyContent = "如果你的看到<b>这个</b>,说明你是在以 <span style=\"color:red\">HTML</span> 格式查看邮件<br><br>";
htmlBodyContent += "<a href=\"http://www.baidu.com//">百度一下</a><img src=\"cid:imageInEmail\"/>";
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(htmlBodyContent, null, "text/html");
LinkedResource lrImage = new LinkedResource("C:\\图片.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg);
lrImage.ContentId = "imageInEmail"; //此处的ContentId 对应 htmlBodyContent 内容中的 cid: ,如果设置不正确,请不会显示图片
htmlBody.LinkedResources.Add(lrImage);
message.AlternateViews.Add(htmlBody);
MailAddress copy = new MailAddress("mailto:CopyToEmail@website.com");
message.CC.Add(copy);
SmtpClient client = new SmtpClient("SMTP Server");
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
}
五、图片为动态生成
public static void SendMail()//带HTML,并且HTML中有图片的邮件发送
{
MailAddress from = new MailAddress("FromEmail@website.com");
MailAddress to = new MailAddress("ToEmail@website.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "邮件标题";
string plainTextBody = "如果你邮件客户端不支持HTML格式,或者你切换到“普通文本”视图,将看到此内容";
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plainTextBody, null, "text/plain"));
string htmlBodyContent = "如果你的看到<b>这个</b>,说明你是在以 <span style=\"color:red\">HTML</span> 格式查看邮件<br><br>";
htmlBodyContent += "<a href=\"http://www.baidu.com//">百度一下</a><img src=\"cid:imageInEmail\"/>";
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(htmlBodyContent, null, "text/html");
- ››ASP.NET及JS中的cookie基本用法
- ››使用linux中的quota教程
- ››ASP.NET获取MS SQL Server安装实例
- ››使用jxl生成带动态折线图的excel
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››使用mysql mysqldump进行数据库迁移
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››使用jquery是新tab形式
更多精彩
赞助商链接