Cannot use Gmail smtp from Azure Cloud Service

后端 未结 5 1877
星月不相逢
星月不相逢 2020-12-10 12:49

My code for sending email through Gmail\'s smtp:

SmtpClient client = new SmtpClient(\"smtp.gmail.com\", 587);
client.EnableSsl = true;
client.UseDefaultCrede         


        
相关标签:
5条回答
  • 2020-12-10 13:24

    It seems your connection is rejected by the SMTP server either because it is not SSL enabled or the credentials are incorrect. You would need to setup SSL and network credentials in your web.config as below:

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

    More info is available in this SO discussion: C# - Can't send mail in WIndows Azure via Gmail SMTP

    0 讨论(0)
  • 2020-12-10 13:24

    As instructed on the Google troubleshooting page, going to the following link and logging in from my local computer fixed the error when sending email from an Azure website for me.

    http://www.google.com/accounts/DisplayUnlockCaptcha

    0 讨论(0)
  • 2020-12-10 13:28

    Use following SMTP settings in Web.config:

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

    I think you are passing wrong credentials. Use @gmail.com suffix in your user name and try to set bodyhtml property true also...

    Hope this will work for you.. It always work correctly to me..

    Check answer's comment in the this SO thread.

    0 讨论(0)
  • 2020-12-10 13:37

    Like said before your username should contain "@googlemail.com". In my code (java) I'm using port 465 to sent mails through google mail.

    0 讨论(0)
  • 2020-12-10 13:44

    I experienced this exact problem. However, I experienced the problem regardless of the fact that I was using the <system.net> configuration settings and I was using the proper credentials, host, port, etc.

    The problem was that Google was rejecting the authentication request that was coming from Azure. I found this out by logging into the Gmail account that I was using for the SMTP Client in my code. Once I logged into the Gmail account, I noticed a red-bar-header-warning that said

    Someone signed in from a location that isn't typical for your account. If it wasn't you, change your password immediately.

    in addition to the warning, I received an email that said:

    Someone recently tried to use an application to sign in to your Google Account, xxxxx@gmail.com. We prevented the sign-in attempt in case this was a hijacker trying to access your account. Please review the details of the sign-in attempt:

    • Monday, August 27, 2012 10:33:59 PM GMT
    • IP Address: 168.62.48.183
    • Location: United States

    If you do not recognize this sign-in attempt, someone else might be trying to access your account. You should sign in to your account and reset your password immediately. Find out how at http://support.google.com/accounts?p=reset_pw

    If this was you, and you want to give this application access to your account, complete the troubleshooting steps listed at http://support.google.com/mail?p=client_login

    Sincerely, The Google Accounts Team

    After I followed the steps listed in the provided link, my Azure Website was able to successfully log into my Gmail account and use Gmail as the SMTP Client.

    0 讨论(0)
提交回复
热议问题