5

I am using a php script to connect imap.gmail.com, I have a paid google app account. It was working but after some time I am getting following error

  1. it says I have to login from browser but my CentsOS vps server does not have a browser its command prompt only

I am using mydomain.com

Fatal error: Uncaught exception 'ImapMailboxException' with message 'Connection error: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco' in /xxxxxx/classes/ImapMailbox.php:51 Stack trace: #0 /home/theluxla/public_html/_backoffice/mailpilot/classes/ImapMailbox.php(42): ImapMailbox->initImapStream() #1 /xxxxxx/classes/ImapMailbox.php(114): ImapMailbox->getImapStream() #2 /xxxxxx/mail.v3.php(28): ImapMailbox->searchMailbox('ALL') #3 {main} thrown in/xxxxx/classes/ImapMailbox.php on line 51

3
  • 2
    Have you tried searching for the error message? A quick search led me to this answer - have you tried any of those suggestions? Jun 27, 2016 at 7:02
  • 1
    It's a security flag. The only real way to get rid of this issue is to use OAuth. But you can try logging in from YOUR browser, and seeing if it asks you to approve the login.
    – Max
    Jun 27, 2016 at 14:09
  • Still my problem is not solved, I was asking about my problem but always somebody will redirect to a different thing Jul 2, 2016 at 4:19

5 Answers 5

8

Google replied to me:

Thank you for your message. I understand you're having issues connecting your application with our IMAP server, I'll be happy to help. I didn't want to bother with a call this early, reason why, I'm sending this email instead In this case, it seems this error is related to the access to "Less secure apps" disabled for the user you're trying to connect via IMAP. Please follow these steps to solve this issue:

  1. In your Admin Console, follow the steps available at this support article https://support.google.com/a/answer/6260879?hl=en under the section "Enabling less secure apps to access accounts".

  2. Log in as the affected user and follow the steps to "Allow less secure apps to access your account" as described at this support article https://support.google.com/accounts/answer/6010255. I hope this information is helpful. Your case will remain open for three business days and it will auto close if no reply is received. Feel free to reply to this message if you need more help, I'll be happy to continue assisting you.

Sincerely,

David

1
  • This was really helpful, since I am working on some old library for IMAP which is just giving unable to loging
    – Sadee
    Sep 20, 2018 at 16:11
7

In may case, Gmail block my server IP

So do the below step to solve this thing.

You need to first Sign in - Google Accounts https://accounts.google.com

You probably need to go here and follow the instructions: https://accounts.google.com/b/0/DisplayUnlockCaptcha

3
  • 2
    This was a real hack actually :) Oct 19, 2020 at 15:08
  • 1
    After several hours of banging my head against the wall, disabling and re-enabling IMAP and less secure app access, thank you sooooo much.
    – Kit
    Oct 26, 2020 at 22:41
  • For me this worked only from within a new (private) Chrome session. Jun 2, 2022 at 19:52
4

Change Gmail accounting setting:-

Enable IMAP.

Status: IMAP is enabledenter image description here

0

https://myaccount.google.com/u/2/security-checkup?utm_source=google-account&utm_medium=web&continue=https%3A%2F%2Fmyaccount.google.com%2Fu%2F2%2Fsecurity

In the “Third-party access” tab turn ON less secure app access

Try to access, you will still be denied

https://myaccount.google.com/u/2/security-checkup?utm_source=google-account&utm_medium=web&continue=https%3A%2F%2Fmyaccount.google.com%2Fu%2F2%2Fsecurity

in the “Recent security events” tab you will find a note about your last access, tell that it was you and you will be able to access

0

In my case none of the proposed answers helped. All options were checked: IMAP -enabled, Less secure apps - enabled, this instruction: https://accounts.google.com/b/0/DisplayUnlockCaptcha also didn't work.

POSSIBLE PROBLEM: use of multiple Gmail accounts (when you connected to many Gmail account and can switch connections). Also if you use the browser like Chrome with profile signed to one of the Google Accounts. In my situation the instruction: https://accounts.google.com/b/0/DisplayUnlockCaptcha didn't work, because I was primarily using browser Chrome profile of my personal Google account, but was working on connection 3rd party app that was using another Google account.

MY SOLUTION. I've added another Chrome profile (corresponding to 3rd Party Gmail Account), switched from my personal profile to working one. And only after that the instruction of https://accounts.google.com/b/0/DisplayUnlockCaptcha gave the positive result. Hope it will save few hours for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.