154

I'm having problems with gmail smtp server. I already read many posts here in StackOverflow about that subject.

The best post I found about test the connection is this one.

Although it is very well explained the error I'm getting I couldn't find a answer: Google SMTP just says "Please log in via your web browser and then try again". I'm completely sure that the password and the email (both in base64) are well encoded.

As you can see here, in this image:

this image,

there is just one difference I can notice: the user@gmail.com and password is sent in two steps. In the link above the guy sends both at the same time. Google didn't accepted that. But the fact is, I write auth login Y29udGF0... (user in base64, googles responds: ) 334 UGFzc3dvcmQ6 (wich means "Password: ") YzQ2MjJmNWVi.... (paste my password in base64 and hit "enter")

Then Goggle says: Please log in via your web browser and then try again. 534-5.7.14 Learn more at https://support.google.com/mail/answer/7126229

And I'm going through all this problem because @MediaTemple and @DreamHost are not working with PHPMailer. I already use PHPMailer for a long time ago, in so many different hosts, using SMTP but failed with (mt) and Dreamhost. Now I'm in middle of a project that it >must< work on these two hosts.

Dibya Sahoo
  • 771
  • 3
  • 8
  • 26
ppalmeida
  • 2,614
  • 5
  • 18
  • 24
  • I know this is old, but, the other way to get this working is to copy the text from the gmail server (that has been edited out from the OP) and modify it so you have a nice long URL string with lots of characters. Then, enter that URL in to your browser and it should work. – vr_driver Jan 09 '18 at 14:17
  • in my case i tried to use *Vercel serverless functions* and turned out it was issue on their end because they don't support smtp stuff. So if case you get here and you use vercel serverless functions, you should use some other provider, not gmail. more details here https://vercel.com/docs/solutions/email – Stanislau Buzunko Oct 31 '20 at 18:04
  • Latest solution using Google app passwords posted [https://stackoverflow.com/questions/43355631/heroku-smtplib-need-to-log-into-browser/64896891#64896891](https://stackoverflow.com/questions/43355631/heroku-smtplib-need-to-log-into-browser/64896891#64896891) – Neil Shah Nov 18 '20 at 16:13

9 Answers9

311

I know this is an older issue, but I recently had the same problem and was having issues resolving it, despite attempting the DisplayUnlockCaptcha fix. This is how I got it alive.

Head over to Account Security Settings (https://www.google.com/settings/security/lesssecureapps) and enable "Access for less secure apps", this allows you to use the google smtp for clients other than the official ones.

Update

Google has been so kind as to list all the potential problems and fixes for us. Although I recommend trying the less secure apps setting. Be sure you are applying these to the correct account.

  • If you've turned on 2-Step Verification for your account, you might need to enter an App password instead of your regular password.
  • Sign in to your account from the web version of Gmail at https://mail.google.com. Once you’re signed in, try signing in
    to the mail app again.
  • Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the
    letters in the distorted picture.
  • Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your account.
  • Make sure your mail app isn't set to check for new email too often. If your mail app checks for new messages more than once every 10
    minutes, the app’s access to your account could be blocked.
Duncan Hoggan
  • 4,727
  • 3
  • 21
  • 28
  • 4
    Recently, I was working on PHPmailer. I was trying to send emails from my local server (WAMP). But, I was not able to send emails because of this error. After spent 2 hrs I found your answer 'Correct' to fix my error. Thank you so much. – Neeraj Singh Aug 14 '14 at 12:18
  • 1
    Thank you so much, this is the missing step i am looking for. thanks – Andoy Abarquez Apr 07 '15 at 09:17
  • 1
    Note to all: You have to do this if you are going to access your account via Outlook as well – Ben Morris Apr 11 '15 at 01:56
  • I can confirm it works! – Claus Oct 15 '15 at 13:21
  • Spent hours wondering why PHPmailer wasn't working - this was it, thanks! – Bahamas Oct 18 '15 at 00:40
  • 1 Thank you so much .. Its useful for me :) – vijay Nov 04 '15 at 04:55
  • Bloody hell... as usual.. this doesn't work for me – user1034912 Dec 28 '15 at 09:58
  • it's no longer working. I turn on Access for less secure apps and I still get the same message as google prevent the login. I have just tried it in AWS EC2 using nodemailer – Mark Thien Jan 12 '16 at 05:03
  • @MarkThien I just tried from my local machine using nodemailer and it worked fine. – Duncan Hoggan Jan 12 '16 at 06:33
  • What the heck...I had to do this to add another Gmail account as a send-as address in Gmail itself! "All Google products use the latest security technologies" my butt. – wizonesolutions Jan 21 '16 at 10:34
  • Saved precious time, this is perfect answer for mentioned scenario. – Chiragit007 Feb 24 '16 at 05:25
  • Thank you very much save my day. I love you <3 – Paul Feb 29 '16 at 09:39
  • 3
    Note that I had to actually TURN ON 2-Step Verification, but once I had this worked. (For some reason beforehand it'd work from one computer but not another.) – Erhannis May 28 '16 at 14:56
  • 1
    thanks so much sir one of my big problem was solved – Remya R Jun 29 '16 at 06:57
  • 1
    I had very tired because search some answers about this problem. Now i found it really I'm very happy!!! Thanks so much Duncan!!! – Sidath Sep 08 '16 at 15:55
  • 1
    You the real MVP thanks. After searching for a solution, this was the one. – Nicolás Santisteban Oct 24 '16 at 13:58
  • 1
    Thank you, thank you, THANK YOU! Google ended up blocking access from my device because it was "new". I added it to the list of accepted devices, but still had to complete the "DisplayUnlockCaptcha" part before it would work. – Kevin M Dec 05 '16 at 20:29
  • @MarkThien did you solve your problem. I'm using AWS EC2 too and I have the exact same problem: http://stackoverflow.com/q/42983283/1817673 – Jorge B. Mar 24 '17 at 09:40
  • it worked locally, but when I deployed to my server it gives me `Please log in via your web browser and then try again`. Gmail is a waste of time, I wish people stop using it in packages – Toolkit May 20 '17 at 04:55
  • 1
    WARNING FOR OTHERS: In my case, setting the Gmail server as shown above worked, but not instantly. They took effect after some minutes (10 maybe?). – Z80 May 08 '21 at 17:00
114

I did this every time the problem happens:

https://accounts.google.com/DisplayUnlockCaptcha

  • problem sorted in my case!
Romain
  • 1,149
  • 1
  • 7
  • 2
  • 4
    This, I don't obviously understand why, works for me (after doing 'less secure' way above) – Abdillah Feb 13 '15 at 16:48
  • I completely agree with @Abdillah. In fact, after this worked for me, Google then sent me an SMS on my cell phone about a suspicious activity and asking to visit google.com/blocked !! – Fr0zenFyr May 20 '15 at 21:54
  • 1
    This worked for me, too. Nothing else worked. Weird, going to the link they provided did not work. Thank you so much for this answer. It's really odd that this doesn't seem to be documented. – James Bowler Jun 10 '16 at 22:27
  • Thank you. It was working great – saravanavelu Sep 26 '16 at 13:39
  • In our case we are using javaxmail with IMAP settings, we sorted out already for other account by turning ON less secure apps; but for a second app we forgot that and the application tried too many times in the server, so our guess is that said device/location got completely blocked for login even after we turned ON less secure apps; anyhow using the provided link above https://accounts.google.com/DisplayUnlockCaptcha we got a message saying "Account access enabled: Please try signing in to your Google account again from your new device or application." which we did and it started working. – a4bike Jun 01 '18 at 14:43
  • Works like a charm. Thanks – jhedm Aug 10 '20 at 05:39
  • I did this and it works great but after some time its giving errors and I need to do this again – Surya nath Jan 18 '21 at 15:32
34

I recently got this message, too, after I switched the data center location of a web application sending through Google SMTP.

The URL that apparently Google means is: https://support.google.com/mail/answer/78754. At that link, one of the steps is to reset your password. Not coincidentally, I also received an email from google with a subject of "Suspicious sign in prevented" that instructed me to change my password.

After resetting my password, I was back to using Google SMTP as usual.

bishop
  • 32,403
  • 9
  • 89
  • 122
  • 2
    Thanks! This is the correct answer. I logged in, I changed my password, and everything worked after that. – f.ardelian Apr 21 '14 at 15:59
  • 1
    in my case, i hade todo both: change the password and after that enable unsecure access, because even after enabling unsecure access, it was reset to disable, without doing anything from my side, very strange. – michabbb Jul 06 '17 at 19:14
  • Also, you need to check the suspicious access allowed with the account you want to use. In that way you can grant access from the instance | server that use your gmail account. After that I update my password and I am ready to go! – Franco Gil Apr 09 '21 at 16:36
22

I know this question is already been answered but for new comers those two solutions may help:

  1. Make sure your gmail is allowing low secure apps to sign in, you can turn it on here: https://www.google.com/settings/security/lesssecureapps.
  2. Change your password.
H Aßdøµ
  • 2,420
  • 3
  • 16
  • 27
10

To send mail using Gmail SMTP, need to change your account setting. Login into your gmail accout then follow the link below to change your gmail account setting to send mail using your apps and program. https://www.google.com/settings/security/lesssecureapps

Note: This setting is not available for accounts with 2-Step Verification enabled. Such accounts require an application-specific password for less secure apps access.

Avnish alok
  • 1,926
  • 19
  • 25
10

There are two ways to resolve this, and only one may work, depending on how you're accessing Google.

The first method is to authorize access for your IP or client machine using the https://accounts.google.com/DisplayUnlockCaptcha link. That can resolve authentication issues on client devices, like mobile or desktop apps. I would test this first, because it results in a lower overall decrease in account security.

If the above link doesn't work, it's because the session is being initiated by an app or device that is not associated with your particular location. Examples include:

  • An app that uses a remote server to retrieve data, like a web site or, in my case, other Google servers
  • A company mail server fetching mail on your behalf

In all such cases you have to use the https://www.google.com/settings/security/lesssecureapps link referenced above.

TLDR; check the captcha link first, and if it doesn't work, try the other one and enable less secure apps.

gamut
  • 665
  • 6
  • 15
2

I also came across this problem. Google detected my Mac as a new device and blocked it. To unblock, in a web browser log in to your Google account and go to "Account Settings".

Scroll down and you'll find "Recent activities". Click just below that on "Devices".

Your device will be listed. Okay your device. SMTP started working for me after I did this and lowered the protection as mentioned above.

Guddo
  • 51
  • 3
0

There are at least these two issues I have observed for this problem: 1) It could be either because your sender username or password might not be correct 2) Or it could be as answered by Avinash above, the security condition on the account. Once you try SendMail using SMTP, you normally get a notification in to your account that it may be an unauthorized attempt to access your account, if not user can follow the link to turn the settings to lessSecureApp. Once this is done and smtp SendMail is tried again, it works.

Yoku
  • 307
  • 4
  • 15
0

Some apps are marked as less secure by google, so you just need to give access for those app so google will allow you to access its services to you.

follow this http://www.codematrics.com/your-imap-server-wants-to-alert-you-to-the-following-please-login-via-your-web-browser-gmail/

Miral Viroja
  • 333
  • 2
  • 10