我正在尝试发送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
答案 0 :(得分:0)
解决方案是在web.config上写下电子邮件所在的正确参数。
<system.net>
<mailSettings>
<smtp from=from@yourdomain.com>
<network host="localhost" password="" userName=""/>
</smtp>
</mailSettings>
</system.net>
现在,如果您的服务器授予localhost发件人权限,则不需要密码和用户名,但如果没有,则需要输入您的电子邮件信息
答案 1 :(得分:0)
我收到了相同的错误消息,但我已通过向 SMTP 凭据提供有效的用户名和密码来解决此问题。在这种情况下需要有效的身份验证。
答案 2 :(得分:-1)
发件人电子邮件地址需要有一个邮箱。您必须从托管中启用它。