开发者

SMTP exception. asking for authentication? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.
protected void Button1_Click(object sender, EventArgs e)
{
    MailMessage message = new MailMessage()
    {
        Subject = "Subject",
        Body = "Body"
    };
    message.To.Add(new MailAddress("demo@example.com", "Some name"));

    SmtpClient client = new SmtpClient();
    client.EnableSsl = true;
    client.Send(message);
}

config

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="de开发者_Go百科mo@example.com">
        <network host="****" defaultCredentials="false"  port="587" userName="****" password="****" />
      </smtp>
    </mailSettings>
  </system.net>
 <system.web>

Correction. it works now. Thanks Marek


Your problem might be with defaultCredentials set to true. Try setting that to false and try again. Also, why are you setting your credentials again in code? Gmail also requires emails to be sent via SSL (if I remember correctly) on port 587.

Just today I implemented gmail smtp in my code. My settings and code:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="MY_GMAIL_EMAIL">
        <network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="MY_GMAIL_USERNAME" password="MY_GMAIL_PASSWORD" />
      </smtp>
    </mailSettings>
  </system.net>


MailMessage message = new MailMessage() {
                              Subject = "Subject",
                              Body = "Body"
                          };
message.To.Add(new MailAddress("someemail@domain.com", "Some name"));
SmtpClient smtpClient = new SmtpClient();
smtpClient.EnableSsl = true;
smtpClient.Send(message);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜