教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 c#使用netmail发送邮件的例子

c#使用netmail发送邮件的例子

发布时间:2016-07-23   编辑:jiaochengji.com
分享一例c#使用netmail发送邮件的代码,很简单,用来研究c#发送邮件的方法还不错,有需要的朋友参考下。

例子,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);
}
}

您可能感兴趣的文章:
c#使用netmail发送邮件的例子
c#使用webmail邮件系统发送邮件的代码
phpmailer发送yahoo邮件的例子
php smtp发送邮件的函数
PHPmailer邮件群发的入门例子
php使用smtp发送邮件的实现代码
phpmailer 类发送邮件乱码解决方法
PHPMailer发送邮件代码实例(ubuntu系统)
php使用Pear的NetMail发送smtp邮件
phpmailer发送网易126邮箱的例子

关键词: netmail  发送邮件   
[关闭]
~ ~