email - 命令顺序错误。服务器响应是 : This mail server requires authentication when attempting to send to a non-local e-mail

标签 email ssl model-view-controller

我正在尝试在 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/

相关文章:

ssl - 使用 SSL 的雅司给出错误 "SSL accept failed: timeout"

model-view-controller - 如何使用 jquery mobile 在页面内创建对话框?

php - 创建 "Engine"以允许集成到主 Web 应用程序?

google-app-engine - 使用 Google App Engine 自定义传入邮件域

python - 如何使用 Python 接收邮件?

在 Centos 上未使用 Shell cmd/脚本发送电子邮件

ios - NSURLSessionAuthChallengeUseCredential 没有帮助。如何让 iOS 信任我的服务器?

c# - 为什么我的客户端无法建立具有权限的 SSL/TLS 安全通道的信任关系?

model-view-controller - 在 MVC 设置中,文本应该在哪里格式化?

database - 我可以使用 NAnt 查询我的数据库并将结果用作参数值吗?