C# - 无法通过Gmail SMTP在Windows Azure中发送邮件 [英] C# - Can't send mail in WIndows Azure via Gmail SMTP

查看:193
本文介绍了C# - 无法通过Gmail SMTP在Windows Azure中发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的web.config:

This is my 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:

My failure SmtpException:

Failure sending mail.

的InnerException:

InnerException:

Unable to connect to the remote server

我在本地测试,但我想它应该工作。我要在Windows Azure上运行它,我想并没有太多工作。是否有什么我失踪?

I'm testing it locally but I guess it should work. I have to run it on Windows Azure, I tried and it didn't work too. Is there something I'm missing?

推荐答案

基本的身份验证和默认的网络凭据选项是互斥的;如果你设置的DefaultCredentials为true,并指定一个用户名和密码,默认的网络凭证时,其基本身份验证数据被忽略。

The basic authentication and default network credentials options are mutually exclusive; if you set defaultCredentials to true and specify a user name and password, the default network credential is used, and the basic authentication data is ignored.

使用

<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>

这篇关于C# - 无法通过Gmail SMTP在Windows Azure中发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆