Ehs*_*bar 5 email model-view-controller ssl
我正在尝试在 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);
}
Run Code Online (Sandbox Code Playgroud)
当我调用此函数时,我收到此错误:
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.
Run Code Online (Sandbox Code Playgroud)
异常详细信息:
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
Run Code Online (Sandbox Code Playgroud)
解决方案是在 web.config 上写入电子邮件所在位置的正确参数。
<system.net>
<mailSettings>
<smtp from=from@yourdomain.com>
<network host="localhost" password="" userName=""/>
</smtp>
</mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)
现在,如果您的服务器向本地主机发件人授予权限,您不需要密码和用户名,但如果不在那里放置您的电子邮件信息
归档时间: |
|
查看次数: |
6602 次 |
最近记录: |