我正在尝试在 asp.net 中发送,所以我有一个功能,您可以在这里看到:
public void SendEmail(string subject, string messageBody, string toAddress)
{
bool ssl = false;
Repository.EmailConfRepository emailConf=new EmailConfRepository();
DomainClass.EmailConfiguration e = emailConf.GetAll().First();
if (e.EnableSsl == "true") ssl = true;
MailMessage mail = new MailMessage();
mail.To.Add(toAddress);
mail.From = new MailAddress(e.EmailFrom);
mail.Subject = subject;
string Body = messageBody;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Host = e.SmtpServer;
smtp.Credentials = new System.Net.NetworkCredential
(e.Username, e.Password);
smtp.Port = int.Parse(e.SmtpPort);
smtp.EnableSsl = ssl;
smtp.Send(mail);
}
当我调用这个函数时,我得到了这个错误:
Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
异常详情:
Exception Details: System.Net.Mail.SmtpException: Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server
最佳答案
解决方案是在 web.config 上写下电子邮件的正确参数。
<system.net>
<mailSettings>
<smtp from=from@yourdomain.com>
<network host="localhost" password="" userName=""/>
</smtp>
</mailSettings>
</system.net>
现在,如果您的服务器将权限授予本地主机发件人,则您不需要密码和用户名,但如果没有,请将您的电子邮件信息放在那里
关于email - 命令顺序错误。服务器响应是 : This mail server requires authentication when attempting to send to a non-local e-mail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29830830/