【问题标题】:C# - Can't send mail in WIndows Azure via Gmail SMTPC# - 无法通过 Gmail SMTP 在 WIndows Azure 中发送邮件
【发布时间】:2011-09-26 18:20:36
【问题描述】:

这是我的 Web.config:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network">
            <network defaultCredentials="true" enableSsl="true" host="smtp.gmail.com" port="25" userName="xxxxxxx@gmail.com" password="xxxxxxxxxxx"/>
        </smtp>
    </mailSettings>
</system.net>

我的方法:

public static void EmailVerification(string email, string nickname)
    {
        MailAddress from = new MailAddress("xxxxxxxxxxx", "xxxxxxxxxxxx");
        MailAddress to = new MailAddress(email);

        MailMessage message = new MailMessage(from, to);

        message.Subject = "Test";
        message.Body = "Test";
        SmtpClient client = new SmtpClient();

        try
        {
            client.Send(message);
        }
        catch(SmtpFailedRecipientException ex)
        {
            HttpContext.Current.Response.Write(ex.Message);
            return;
        }
    }

我的失败 SmtpException:

Failure sending mail.

内部异常:

Unable to connect to the remote server

我正在本地测试它,但我想它应该可以工作。我必须在 Windows Azure 上运行它,我试过了,但也没有用。我有什么遗漏吗?

【问题讨论】:

标签: azure smtpclient


【解决方案1】:

基本身份验证和默认网络凭据选项是互斥的;如果将 defaultCredentials 设置为 true 并指定用户名和密码,则使用默认网络凭据,而忽略基本身份验证数据。

使用

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network">
            <network enableSsl="true" host="smtp.gmail.com" port="25" userName="xxxxxxx@gmail.com" password="xxxxxxxxxxx"/>
        </smtp>
    </mailSettings>
</system.net>

【讨论】:

  • 我明白了,我是这样使用的: 我需要把端口改成587
猜你喜欢
  • 1970-01-01
  • 2020-02-21
  • 2018-11-13
  • 2018-09-13
  • 2015-07-25
  • 2013-10-28
  • 2021-05-08
  • 2014-08-27
  • 1970-01-01
相关资源
最近更新 更多