SMTP 异常。要求认证?

发布于 2024-11-06 09:35:32 字数 967 浏览 0 评论 0原文

protected void Button1_Click(object sender, EventArgs e)
{
    MailMessage message = new MailMessage()
    {
        Subject = "Subject",
        Body = "Body"
    };
    message.To.Add(new MailAddress("[email protected]", "Some name"));

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

配置

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="****" defaultCredentials="false"  port="587" userName="****" password="****" />
      </smtp>
    </mailSettings>
  </system.net>
 <system.web>

修正。现在可以了。谢谢马雷克

protected void Button1_Click(object sender, EventArgs e)
{
    MailMessage message = new MailMessage()
    {
        Subject = "Subject",
        Body = "Body"
    };
    message.To.Add(new MailAddress("[email protected]", "Some name"));

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

config

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="****" defaultCredentials="false"  port="587" userName="****" password="****" />
      </smtp>
    </mailSettings>
  </system.net>
 <system.web>

Correction. it works now. Thanks Marek

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云归处 2024-11-13 09:35:32

您的问题可能是 defaultCredentials 设置为 true。尝试将其设置为 false,然后重试。另外,为什么要在代码中再次设置凭据? Gmail 还要求通过 SSL(如果我没记错的话)在端口 587 上发送电子邮件。

就在今天,我在代码中实现了 gmail smtp。我的设置和代码:

<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("[email protected]", "Some name"));
SmtpClient smtpClient = new SmtpClient();
smtpClient.EnableSsl = true;
smtpClient.Send(message);

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("[email protected]", "Some name"));
SmtpClient smtpClient = new SmtpClient();
smtpClient.EnableSsl = true;
smtpClient.Send(message);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文