Search code examples
gmailcontainersbitbucketimapbitbucket-pipelines

GMAIL IMAP read fails due to authentication when used in bitbucket pipeline


This call (imap_open()) has been failing consistently when I run the script inside a docker container run by bitbucket pipeline.

PHP Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in /opt/atlassian/pipelines/agent/build/test/tools/plib/confirm.php on line 24 PHP Fatal error: Uncaught exception 'Exception' with message 'signup: confirm failed' in /opt/atlassian/pipelines/agent/build/test/tools/plib/signup.php:24 Stack trace: #0 /opt/atlassian/pipelines/agent/build/test/tools/test.php(51): signup(Array) #1 {main} thrown in /opt/atlassian/pipelines/agent/build/test/tools/plib/signup.php on line 24 PHP Notice: Unknown: Retrying PLAIN authentication after [ALERT] Please log in via your web browser: https://support.google.com/mail/acco (errflg=1) in Unknown on line 0 PHP Notice: Unknown: Retrying PLAIN authentication after [ALERT] Please log in via your web browser: https://support.google.com/mail/acco (errflg=1) in Unknown on line 0 PHP Notice: Unknown: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco (errflg=2) in Unknown on line 0 Cannot connect to Gmail: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco

I have followed all these instructions:

  1. Enabled less secure apps
  2. Enabled from https://accounts.google.com/b/0/DisplayUnlockCaptcha
  3. Tried with and without /novalidate-cert flag

Same script works fine when run locally within the Mac OS or even with AWS EC2 instance but fails when run by bitbucket or Heroku. There is no way I can run a browser on these instances, so cannot try web interface and apparently once enabled for access, it should work every where.

Too bad, the link in the error message isn't even complete.

Any idea how to overcome this? All I want to do is to simply simulate a click on the verify link in a signup email programmatically.


Solution

  • As mentioned , google does alert "Less secured apps" and authentication keeps failing even after that sometimes. Best solution here is to move to OAUTH2 auth method, else even if you find a way to solve this "less secured alert" issue... it may eventually occur in future on and off.