最近邮件发送总是提示发送失败,错误提示如下图:
1 /// <summary> 2 /// 处审核后类的实例 3 /// </summary> 4 /// <param name="To">收件人地址[di zhi]</param> 5 /// <param name="From">发件人地址[di zhi]</param> 6 /// <param name="Body">邮件[you jian]正文[zheng wen]</param> 7 /// <param name="Title">邮件[you jian]的主题</param> 8 /// <param name="Password">发件人密码[mi ma]</param> 9 public SendMailAction(string To, string From, string Body, string Title, string Password, int port, string host) 10 { 11 mailMessage = new MailMessage(); 12 mailMessage.To.Add(To); 13 mailMessage.From = new System.Net.Mail.MailAddress(From); 14 mailMessage.Subject = Title; 15 mailMessage.SubjectEncoding = Encoding.UTF8; 16 mailMessage.Body = Body; 17 mailMessage.IsBodyHtml = true; 18 mailMessage.BodyEncoding = System.Text.Encoding.UTF8; 19 mailMessage.Priority = System.Net.Mail.MailPriority.Normal; 20 this.password = Password; 21 this.port = port; 22 this.host = host; 23 } 24 25 /// <summary> 26 /// 发送邮件[you jian] 27 /// </summary> 28 public void Send() 29 { 30 if (mailMessage != null) 31 { 32 smtpClient = new SmtpClient(); 33 smtpClient.UseDefaultCredentials = false; 34 smtpClient.Credentials = new System.Net.NetworkCredential(mailMessage.From.Address, password);//设置[she zhi]发件人身份[shen fen]的票据 35 smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 36 smtpClient.Host = this.host; 37 smtpClient.Port = this.port; 38 smtpClient.EnableSsl = true; 39 //smtpClient.Timeout = 180000; 40 //smtpClient.SendCompleted += new SendCompletedEventHandler(CompletedMethod);//注册[zhu ce]异步[yi bu]发送邮件[you jian]完成时的事件[shi jian] 41 //smtpClient.SendAsync(mailMessage, mailMessage.Body); 42 43 smtpClient.Send(mailMessage); 44 } 45 }
邮件是否支持smtp服务,smtp服务打开没有
不是这个问题,之前测试的时候是可以的,后面不行了,邮箱账户也没有问题
@KunLen: 我发个demo吧
protected void Page_Load(object sender, EventArgs e) { SendEmail("867214862@qq.com", "test-title", "你好啊!"); }
#region /// <summary> /// 发送邮件 /// </summary> /// <param name="mailTo">要发送的邮箱</param> /// <param name="mailSubject">邮箱主题</param> /// <param name="mailContent">邮箱内容</param> /// <returns>返回发送邮箱的结果</returns> public static void SendEmail(string mailTo, string mailSubject, string mailContent) { // 设置发送方的邮件信息,例如使用网易的smtp string smtpServer = "smtp.qq.com"; //SMTP服务器 string mailFrom = "2574146995@qq.com"; //登陆用户名 string userPassword = "zx147285";//登陆密码
// 邮件服务设置 SmtpClient smtpClient = new SmtpClient(); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 smtpClient.Host = smtpServer; //指定SMTP服务器 smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userPassword);//用户名和密码
MailAddress from = new MailAddress("2574146995@qq.com", "红装", Encoding.UTF8);
MailAddress to = new MailAddress("867214862@qq.com");
MailMessage message = new MailMessage(from, to); message.Body = "This is a test e-mail message sent by an application. "; // Include some non-ASCII characters in body and subject. message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = "七夕节!"; message.SubjectEncoding = System.Text.Encoding.UTF8;
smtpClient.Send(message);
HttpContext.Current.Response.Write("ok");
} #endregion