第一步:查看类 这里使用的是新浪的邮件服务器ing System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net.Mail;
/// <summary>/// SendMail 的摘要说明/// </summary>public class SendMail{ public SendMail() { // // TODO: 在此处添加构造函数逻辑 // } /// <summary> /// 发送电子邮件 /// </summary> /// <param name="MessageFrom">发件人邮箱地址 </param> /// <param name="MessageTo">收件人邮箱地址 </param> /// <param name="MessageSubject">邮件主题 </param> /// <param name="MessageBody">邮件内容 </param> /// <returns> </returns> public static string Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody) { MailMessage message = new MailMessage();
message.From = MessageFrom; message.To.Add(MessageTo); //收件人邮箱地址可以是多个以实现群发 message.Subject = MessageSubject; message.Body = MessageBody; message.IsBodyHtml = true; //是否为html格式 message.Priority = MailPriority.High; //发送邮件的优先等级
SmtpClient sc = new SmtpClient(); sc.Host = ""; //指定发送邮件的服务器地址或IP (如:smtp.sina.com) sc.Port = 25; //指定发送邮件端口 sc.Credentials = new System.Net.NetworkCredential("", ""); //指定登录服务器的用户名和密码 (如:"willsonu88","yxd5387832") try { sc.Send(message); //发送邮件 } catch (SmtpException ex) { return ex.Message; } return "邮件发送成功"; }第二步:如果此时仍不能发送的话:请查看你的网络的TCP/IP协议其中有一项DNS服务器配置改为:210.22.70.3还有一项备用DNS服务器配置设置为:202.96.209.6此时一定可以发送成功,试试看