Can't auth to Gmail smtp via MailMessage & smtpClient

后端 未结 11 1273
遇见更好的自我
遇见更好的自我 2020-11-30 06:55

I cannot figure out for the life of my why this isn\'t working

SmtpClient smtp = new SmtpClient
{
    Host = \"smtp.gmail.com\",
    Port = 587,
    UseDefau         


        
相关标签:
11条回答
  • 2020-11-30 07:31

    It looks like Gmail requires Application-specific password(not your main password).

    Please, look into this: http://support.google.com/mail/bin/answer.py?hl=en&answer=1173270

    I had the same problem recently.

    0 讨论(0)
  • 2020-11-30 07:31

    For me the solution required 2 "steps":

    • set UseDefaultCredentials = false first, then set the credentials I want to use Credentials = new NetworkCredential("myemail@gmail.com", "myGmailPasswordHere"). Setting the credentials first, when I set UseDefaultCredentials = false will make the Credentials property null.
    • Allow less secure apps on my Google profile.
    0 讨论(0)
  • 2020-11-30 07:35

    Had the same issue accessing smtp.gmail.com from an ASP.NET application running on Amazon AWS hosting. It turned out that my configuration was right - it was also working fine from another computer - but gmail would deny my login attempt, because I try logging in from an unusual location. I logged on to gmail over the web interface (www.gmail.com), and had to answer a captcha. After that it worked.

    0 讨论(0)
  • 2020-11-30 07:35

    My problem was that the domain-owner for our gmail-account had disabled both "Access for less secure apps" and two step authentication. There was no way to enable it, I couldn't even see the setting. So I tested with my personal account instead, and it worked fine.

    0 讨论(0)
  • 2020-11-30 07:36

    If login info is 100% right, you need to set UseDefaultCredentials = false first and then set the credentials you want to use Credentials = new NetworkCredential("myemail@gmail.com", "myGmailPasswordHere").

    If you set the credentials first, when you set UseDefaultCredentials = false this will make the Credentials property to null.

    This is wired, but it happened to me.

    Debug your code and check if the Credentials property is null before you call smtp.Send(message);. If so, then try inverting the order. It seems you have it in the right order, but if it's null, don't use the inline initialization.

    Hope it helps.

    EDIT: If you are using two-step verification, be sure you are using an App Specific password

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