如果你的ASPNET程序学得不错了想用ASPNET来发送邮件在网上有好多文章本站不管网上说是如何实现的下面整理两种NET发送邮件的方法给你参考一下很简单的哦
第一种
配置文件(nfig) + 少量C#代码
在 configuration 节点下添加
<> <mailSettings> <smtp from=> <network host= password=baidu port= userName=baidu defaultCredentials=false/> </smtp> </mailSettings> </>
/// <summary>
/// 发送邮件/// </summary>private void SendMail(){ SystemNetMailMailMessage message = new SystemNetMailMailMessage(); messageFrom = new SystemNetMailMailAddress();//发送人邮箱地址与smtp节点中的from值一致 messageToAdd(new SystemNetMailMailAddress());//接收人邮箱地址 messageSubject = hello; messageBody = <b>taobao</b>; messageIsBodyHtml = true; SystemNetMailSmtpClient smtpclient = new SystemNetMailSmtpClient(); smtpclientSend(message);}
好介绍完第一种发送邮件的方法下面看第二种
/// <summary>
/// 发送邮件/// </summary>private void SendMail(){ SystemNetMailMailMessage message = new SystemNetMailMailMessage(); messageFrom = new SystemNetMailMailAddress();//发送人邮箱地址与smtp节点中的from值一致 messageToAdd(new SystemNetMailMailAddress());//接收人邮箱地址 messageSubject = hello; messageBody = <b>taobao</b>; messageIsBodyHtml = true; SystemNetMailSmtpClient smtpclient = new SystemNetMailSmtpClient( ); smtpclientCredentials = new SystemNetNetworkCredential(baidu baidu);//参数分别是邮箱用户名和密码 smtpclientSend(message);}
怎样上面两种发送邮件的方法都很简单吧