本文介绍了如何使用C#asp.net应用程序发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
发送短信时会产生以下错误-----------
错误:SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。了解更多信息
使用系统;
使用 System.Data;
使用 System.Configuration;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Web.UI.HtmlControls;
使用 System.Net;
使用 System.Net.Mail;
-------------------------------------
string Subject = 这是测试邮件使用smtp设置,
Body = txtMessage.Text.Trim(),
ToEmail = txtToEmail.Text.Trim();
string SMTPUser = [email protected],SMTPPassword = 96511993122222;
// 现在实例化MailMessage的新实例
MailMessage mail = new MailMessage();
// 设置邮件的发件人地址
mail.From = new System.Net.Mail.MailAddress(SMTPUser, [email protected]跨度>);
// 设置邮件的接收地址
mail.To.Add(ToEmail);
// 设置邮件主题
mail .Subject =主题;
// 设置邮件正文
mail .Body =身体;
// 即使你没有发送HTML消息也要保持原样
mail.IsBodyHtml = true ;
// 将邮件的优先级设置为正常
mail.Priority = System.Net.Mail.MailPriority.Normal;
// 实例化SmtpClient的新实例
SmtpClient smtp = new SmtpClient();
// 如果您使用的是smtp服务器,请将主机更改为smtp。 yourdomain.com
smtp.Host = smtp.gmail.com;
// 为您的主机输入您的端口
smtp。端口= 587 ; // 或者您也可以使用#587端口
// 提供smtp凭据以对您的帐户进行身份验证
smtp.Credentials = new System.Net.NetworkCredential(SMTPUser,SMTPPassword);
// 如果您使用SSL / TLS使用安全身份验证,则trueelse false
smtp.EnableSsl = true ;
smtp.UseDefaultCredentials = false ;
smtp.Send(mail);
lblMsg.Text = 成功:邮件发送成功!;
lblMsg.ForeColor = System.Drawing.Color.Green;
解决方案
following error is generate while sending sms-----------
Error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
using 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; using System.Net.Mail; ------------------------------------- string Subject = "This is test mail using smtp settings", Body = txtMessage.Text.Trim(), ToEmail = txtToEmail.Text.Trim(); string SMTPUser = "[email protected]", SMTPPassword = "96511993122222"; //Now instantiate a new instance of MailMessage MailMessage mail = new MailMessage(); //set the sender address of the mail message mail.From = new System.Net.Mail.MailAddress(SMTPUser, "[email protected]"); //set the recepient addresses of the mail message mail.To.Add(ToEmail); //set the subject of the mail message mail.Subject = Subject; //set the body of the mail message mail.Body = Body; //leave as it is even if you are not sending HTML message mail.IsBodyHtml = true; //set the priority of the mail message to normal mail.Priority = System.Net.Mail.MailPriority.Normal; //instantiate a new instance of SmtpClient SmtpClient smtp = new SmtpClient(); //if you are using your smtp server, then change your host like "smtp.yourdomain.com" smtp.Host = "smtp.gmail.com"; //chnage your port for your host smtp.Port =587; //or you can also use port# 587 //provide smtp credentials to authenticate to your account smtp.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword); //if you are using secure authentication using SSL/TLS then "true" else "false" smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; smtp.Send(mail); lblMsg.Text = "Success: Mail sent successfully!"; lblMsg.ForeColor = System.Drawing.Color.Green;
解决方案
这篇关于如何使用C#asp.net应用程序发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!