[置顶] C# 邮件发送方法【NetMail方式】
2011-12-23 11:03
330 查看
在上一篇博文C# 邮件发送方法【webMail方式】中介绍了Webmail的邮件发送方式,现在介绍下C#中使用NetMail发送邮件的方式,
测试代码如下:
/// <summary>
/// NetMail方式测试通过
/// </summary>
private void TestSend()
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
//收件人地址
mm.To.Add(new System.Net.Mail.MailAddress("xxxxxx@163.com", "Name"));
//发件人地址
mm.From = new System.Net.Mail.MailAddress("xxxxx@sina.com");
//这个可以不指定
//mm.Sender = new System.Net.Mail.MailAddress("xxx@sina.com", "SenderName");、
mm.Subject = "This is Test Email";
mm.Body = "<h3>This is Testing SMTP Mail Send By Me</h3>";
mm.IsBodyHtml = true;
mm.Priority = System.Net.Mail.MailPriority.High; // 设置发送邮件的优先级
System.Net.Mail.SmtpClient smtCliend = new System.Net.Mail.SmtpClient();
//指定邮件服务器
smtCliend.Host = "smtp.sina.com";
//smtp邮件服务器的端口号
smtCliend.Port = 25;
//设置发件人邮箱的用户名和地址,使用公共邮件服务器一般需要提供,不然发送不会成功
smtCliend.Credentials = new NetworkCredential("xxxxxxx", "xxxxxxx");
//指定邮件的发送方式
smtCliend.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try
{
smtCliend.Send(mm);
}
catch (System.Net.Mail.SmtpException ex)
{
Response.Write(ex.Message);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
测试代码如下:
/// <summary>
/// NetMail方式测试通过
/// </summary>
private void TestSend()
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
//收件人地址
mm.To.Add(new System.Net.Mail.MailAddress("xxxxxx@163.com", "Name"));
//发件人地址
mm.From = new System.Net.Mail.MailAddress("xxxxx@sina.com");
//这个可以不指定
//mm.Sender = new System.Net.Mail.MailAddress("xxx@sina.com", "SenderName");、
mm.Subject = "This is Test Email";
mm.Body = "<h3>This is Testing SMTP Mail Send By Me</h3>";
mm.IsBodyHtml = true;
mm.Priority = System.Net.Mail.MailPriority.High; // 设置发送邮件的优先级
System.Net.Mail.SmtpClient smtCliend = new System.Net.Mail.SmtpClient();
//指定邮件服务器
smtCliend.Host = "smtp.sina.com";
//smtp邮件服务器的端口号
smtCliend.Port = 25;
//设置发件人邮箱的用户名和地址,使用公共邮件服务器一般需要提供,不然发送不会成功
smtCliend.Credentials = new NetworkCredential("xxxxxxx", "xxxxxxx");
//指定邮件的发送方式
smtCliend.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try
{
smtCliend.Send(mm);
}
catch (System.Net.Mail.SmtpException ex)
{
Response.Write(ex.Message);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
相关文章推荐
- [置顶]C# 邮件发送方法【NetMail方式】
- [置顶]C# 邮件发送方法【webMail方式】
- [置顶] C# 邮件发送方法【webMail方式】
- C# 邮件发送方法【NetMail方式】
- C# 邮件发送方法【NetMail方式】
- c#使用netmail方式发送邮件示例
- C# 邮件发送方法【webMail方式】
- C# 邮件发送方法【webMail方式】
- c#使用netmail方式发送邮件示例
- C# 邮件发送方法【webMail方式】
- [导入]C#发送Email邮件方法总结
- C#发送Email邮件方法总结
- C#发送邮件的方法及实例代码
- vs2005中发送邮件的方法(C#)
- C#中利用Lotus notes公共邮箱发送邮件的方法
- C#发送Email邮件方法总结
- C#编写的邮件(Mail)发送发送人的信息从web.config或者从Appp.congfig中获取的方法
- C#发送Email邮件方法总结
- C#邮件发送CDO的COM组件发送方式
- 在.NET中发送邮件,使用回执功能中遇到问题的解决方法[在NOTES服务器上,C#,.NET2.0环境]