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
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.
For me the solution required 2 "steps":
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
.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.
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.
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