After upgrading to SMTP 8.x-1.0-beta7, I am seeing the following error on the Status Report page --

SMTP module is enabled, turned on, but SmtpConnect() threw exception SMTP Error: Could not authenticate.

This is because the new Drupal\smtp\ConnectionTester\ConnectionTester class added in #3101303: Add hook_requirements() to Drupal 8 version has an operator precedence issue when attempting to set the $username and $password variables in a single if statement. $username ends up being set to TRUE instead of the config value.

A simple fix is to break out those assignments before the if statement. Patch incoming.

Comments

wells created an issue. See original summary.

wells’s picture

wells’s picture

Status: Active » Needs review
wells’s picture

StatusFileSize
new1.16 KB

Oops, one additional fix needed to fully resolve this -- the setting of $mailer->SMTPSecure was using a comparison instead of assignment operator.

morenstrat’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, fixes the problem, patch looks good, too.

arnoldbird’s picture

Status: Reviewed & tested by the community » Active

The patch doesn't fix the issue for me. I applied this patch: smtp_error_could_not_authenticate-3114989-3.patch

In my status report, I still see "SMTP module is enabled, turned on, but SmtpConnect() threw exception SMTP Error: Could not authenticate."

I tried sending a test email with the SMTP module, just to see if the error is a false positive, but the email was not delivered.

morenstrat’s picture

@arnolbird Sending a test e-mail worked for me even without the patch. Maybe you have a different problem? Have you double-checked that your credentials are correct?

wells’s picture

Status: Active » Reviewed & tested by the community

Indeed. The symptoms here are seeing this error when email delivery works.

rivimey’s picture

Can I suggest another change:

Change the lines that set SMTPSecure from:

     $mailer->SMTPSecure == in_array($this->configGet('smtp_protocol'), ['ssl', 'tls']) ? $this->configGet('smtp_protocol') : '';

to:

      $protocol = $this->configGet('smtp_protocol');
      $mailer->SMTPSecure = in_array($protocol, ['ssl', 'tls']) ? $protocol : '';

which is simpler, faster and doesn't exceed the code standard line length.

tiikeri’s picture

Applying the patch make the error gone away for me too.

klemendev’s picture

The patch from comment #4 fixed the error in our case too and the module works properly.

wells’s picture

Re: #9 I agree that would be a good change. The related files have a number of coding standards issues so I figure that makes more sense to handle in a separate ticket. I was keeping my patch to just fixing the issue.

lisa.rae’s picture

Status: Reviewed & tested by the community » Needs work

Marking Needs Work per comments

wells’s picture

Status: Needs work » Reviewed & tested by the community

To clarify the comments: the patch in #4 has been RTBC'd by #5, #10 and #11. Other comments are unrelated to the issue this patch fixes.

Reverting to RTBC.

jungle’s picture

StatusFileSize
new2.85 KB
new2.48 KB

Refactored according to #9, which is good for me, avoid calling $this->configGet('smtp_protocol') twice, and setted the third parameter strict of in_array to TRUE. Meanwhile, fixed coding standard violations

jungle’s picture

Status: Reviewed & tested by the community » Needs review

The last submitted patch, 15: 3114989-15.patch, failed testing. View results

jungle’s picture

StatusFileSize
new3.63 KB
new3.27 KB

Fix test

rmcom’s picture

subscribing

lomale@bluewin.ch’s picture

Hi I got this message as well

SMTP CONNECTION SMTP module is enabled, turned on, but SmtpConnect() threw exception SMTP Error: Could not authenticate.

Drupal 8.8.4 and SMTP Authentication Support 8.x-1.0-beta7

I asked my host provider. All the settings are correct.
And I can also send mails.
Does this have consequences??

In the meantime I was able to get a debug report.
I append it here.

jungle’s picture

Hi @lomale, applying the patch attached will get the error gone. it does not have serious consequence. Just only show you wrong error info on the status report page even it's correct, nothing more.

rmcom’s picture

Thank you for fixing this!

It would be great to include it in the next release.

sagesolutions’s picture

Status: Needs review » Reviewed & tested by the community

#18 patch works for me as well. Marking as RTBC

EktaPuri’s picture

Patch is not working for Drupal 8.8.3 version. Any help is appreciated

jungle’s picture

Re:#24 The tests against 8.8.x passed, https://www.drupal.org/pift-ci-job/1617443 and one of my Drupal 8.8.3 instances with this patch appiled works as expected.

th.sigit’s picture

patch in #18 seems working for me for one staging and one dev sites.

Module version 8.x-1.0-beta7 Drupal 8.8.3

destinationsound’s picture

Patch in #18 worked for me too. Thanks!

kris77’s picture

Patch in #18 worked for me too. Thanks @jungle

publishing future’s picture

Patch in #18 did NOT solve the problem for me with Drupal 8.8.4. Still the same error message in SMTP module when sending a test email and in watchdog.

wells’s picture

#29 — Please confirm, does the email actually send? This bug relates to getting that error message even though the email sends successfully (i.e. you will still get the error legitimately if there is an actual issue with your SMTP module config).

xdequinze’s picture

#30 I confirm I still have the same problem with 8.8.4. Test email is sent successfully and the error appears on the status report (but no error in the log).

arnoldbird’s picture

If you see an error like I saw in #6, it can be because of changes at Google (our SMTP provider). In my case, my colleague had to adjust the security settings in the Google account to get things working again. In other words, it was not a Drupal issue in my case.

publishing future’s picture

No, emails are actually NOT sent. I double checked the credentials for authentication and they are correct.

wells’s picture

#31 -- could you enable debugging in SMTP and send a log? Also, could you test with the patch from #3? I am still using that one and I have updated multiple sites to 8.8.4 with the patch and no issue.

#33 -- if mail is not sending, I recommend opening a separate issue with more details. This issue only covers the case of getting the error message even though mail send is working fine.

publishing future’s picture

Finally it turned out that an update on the mailserver caused the authentication problem. As this is fixed now, the patch also works for me.

r4arnys’s picture

I used #18's patch and it seems to have worked. (drupal 8.8.4)

lomale@bluewin.ch’s picture

Version: 8.x-1.x-dev » 8.x-1.0-beta7
Issue tags: +SMTP Error: Could not connect to SMTP host

Hi I come back once more.

I still this message as well

SMTP CONNECTION SMTP module is enabled, turned on, but SmtpConnect() threw exception SMTP Error: Could not authenticate.

Drupal 8.8.4 and SMTP Authentication Support 8.x-1.0-beta7

I asked my host provider. All the settings are correct.
And I can also send mails.
Does this have consequences??

In the meantime I was able to get a debug report.
I append it here:

SMTP module is enabled, turned on, but SmtpConnect() threw exception SMTP-Fehler

Ein AJAX-HTTP-Fehler ist aufgetreten.
HTTP-Rückgabe-Code: 200
Im Folgenden finden Sie Debugging-Informationen.
Pfad: /de/batch?id=1583&op=do_nojs&op=do
Statustext: parsererror
Antworttext: SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 asmtp013.mail.hostpoint.ch ESMTP Exim 4.92.3 Thu, 26 Mar 2020 21:57:16 +0100
"
SMTP -> get_lines(): $data is "220 asmtp013.mail.hostpoint.ch ESMTP Exim 4.92.3 Thu, 26 Mar 2020 21:57:16 +0100
"
SMTP -> FROM SERVER:220 asmtp013.mail.hostpoint.ch ESMTP Exim 4.92.3 Thu, 26 Mar 2020 21:57:16 +0100
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
"
SMTP -> get_lines(): $data was "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
"
SMTP -> get_lines(): $str is "250-SIZE 52428800
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
"
SMTP -> get_lines(): $data was "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
"
SMTP -> get_lines(): $str is "250-8BITMIME
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
"
SMTP -> get_lines(): $data was "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
"
SMTP -> get_lines(): $str is "250-PIPELINING
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
"
SMTP -> get_lines(): $data was "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
"
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data was "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $str is "250-STARTTLS
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $data was "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $str is "250 HELP
"
SMTP -> get_lines(): $data is "250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
"
SMTP -> FROM SERVER: 250-asmtp013.mail.hostpoint.ch Hello s32.server.hostpoint.ch [2a00:d70:0:b::1:20]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6
"
SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6
"
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6
"
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6
"
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "235 Authentication succeeded
"
SMTP -> get_lines(): $data is "235 Authentication succeeded
"
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 OK
"
SMTP -> get_lines(): $data is "250 OK
"
SMTP -> FROM SERVER:250 OK
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 Accepted
"
SMTP -> get_lines(): $data is "250 Accepted
"
SMTP -> FROM SERVER:250 Accepted
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "354 Enter message, ending with "." on a line by itself
"
SMTP -> get_lines(): $data is "354 Enter message, ending with "." on a line by itself
"
SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 OK id=1jHZZ2-000Fe3-7Y
"
SMTP -> get_lines(): $data is "250 OK id=1jHZZ2-000Fe3-7Y
"
SMTP -> FROM SERVER:250 OK id=1jHZZ2-000Fe3-7Y
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "221 asmtp013.mail.hostpoint.ch closing connection
"
SMTP -> get_lines(): $data is "221 asmtp013.mail.hostpoint.ch closing connection
"
SMTP -> FROM SERVER:221 asmtp013.mail.hostpoint.ch closing connection
{"status":true,"percentage":"3","message":"Sent 1 of 34 messages.","label":""}

I can send emails.

Can someone give me the exact code I have to write for a correct patch. i.e. #18 or is there a new one.
I'm not very familiar with Terminal commands.
will there be a module update soon.

Thanks Lothar

PS I tested on the Weekend. The mails get out, Functionality is given, but it's an nasty bug with the coming back Errormessage.

wells’s picture

#37 -- That is indeed the bug this ticket relates to in beta7. The patch in #18 resolves the issue but has not been applied and committed yet so if you want to use it, you'll need to configure your Drupal instance to apply it. See Apply Drupal 8 Patch by Composer without update Drupal Core for a basic introduction to how to apply patches via Composer.

gobnat’s picture

When I try to apply the patch in #18 on my dev site I get the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - webflo/drupal-core-require-dev 8.8.4 requires behat/mink 1.7.x-dev -> no matching package found.
    - webflo/drupal-core-require-dev 8.8.4 requires behat/mink 1.7.x-dev -> no matching package found.
    - Installation request for webflo/drupal-core-require-dev 8.8.4 -> satisfiable by webflo/drupal-core-require-dev[8.8.4].

I have never had it before on composer updates or installs. Can anyone clarify why it would be happening?

rivimey’s picture

The problem with composer is unrelated to the patch. You should modify your composer.json such that the version constraint on behat/mink is "~1.8", then rerun composer. I had a similar issue which seems to result from mink v1.7 no longer being available.

dqd’s picture

$ git apply -v 3114989-18.patch
Checking patch src/ConnectionTester/ConnectionTester.php...
Checking patch tests/src/Unit/ConnectionTester/ConnectionTesterTest.php...
Applied patch src/ConnectionTester/ConnectionTester.php cleanly.
Applied patch tests/src/Unit/ConnectionTester/ConnectionTesterTest.php cleanly.

RTBC from here.

promo-il’s picture

#18 3114989-18.patch OK php7.1 D:8.8.5

dqd’s picture

Issue tags: -SMTP Error: Could not connect to SMTP host

@ #37: Before adding tags read the issue tag guidelines. Do NOT use tags for adding random keywords or duplicating any other fields. Separate terms with a comma, not a space.

dqd’s picture

Version: 8.x-1.0-beta7 » 8.x-1.x-dev

Patches should usually be applied against latest dev to commit to HEAD. Lucky enough latest Beta seems to be the same than latest dev so we need no reroll.

dqd’s picture

@#18 / #4 while I have confirmed the patches as RTBC already before, I strongly recommend NOT to add cosmetic changes in issues they do not belong to (I have seen some of them in the patches). And at least - IF - then please report them here for tracking them down later. Apart form that +1 for the fixes provided. Code looks good, patch applies on dev also and do not add any harm. Fixes the issue without drawbacks.

klemendev’s picture

I can confirm the patch works fine on 2 production sites too.

bkosborne’s picture

+1, please let's get this in. Wasted an hour debugging this alarming status message even though everything is fine.

  • japerry committed 3ecdac2 on 8.x-1.x authored by jungle
    Issue #3114989 by jungle, wells: SMTP Error: Could not authenticate.
    
japerry’s picture

Status: Reviewed & tested by the community » Fixed

Yup, looks good to me too. Fixed!

dqd’s picture

+1!

bkosborne’s picture

Thank you

klemendev’s picture

Thanks! :)

lomale@bluewin.ch’s picture

Uups it's me
With Drupal Version 8.8.4
i was happy that we had a Update.
SMTP Authentication Support 8.x-1.0-beta7
recommended Version:
8.x-1.0-rc1 (2020-May-08)

I installed it and NEW, I wasn't able to start the status report.
The website encountered an unexpected error, please try later.

i rolled back to beta 7 and the error dissappeared. I have no specific error log messages.
I could show it on 3 other local project's.

I also tried the newest Drupal Version 8.8.5 and both settings on other platforms. Same error.

Just for information.

lomale@bluewin.ch’s picture

Status: Fixed » Active
Issue tags: +error, +status report
rmcom’s picture

@lomale : it is likely due to the introduction of the PHPMailer library

see https://www.drupal.org/project/smtp/issues/3135015

japerry’s picture

Status: Active » Fixed

Yup, RC2 should help you find your issue here. Which is likely due to missing the PHPMailer library. This issue itself should be fixed though.

lomale@bluewin.ch’s picture

YEP rc2 worked also for me.
It show's correctly : missing the PHPMailer library
Thanks

lomale@bluewin.ch’s picture

StatusFileSize
new442.77 KB

Yes I made it to apply with

composer update drupal/smtp --with-dependencies

the phpmailer library

the error in status report that shows correctly Comment #57 has gone

i ad a picture SMTP Module.png where I found the PHP Mailer
under src in SMTP Module

The sending of the email works, but still an error message. I think nothing critical but anoying.

Error copy

Ein AJAX-HTTP-Fehler ist aufgetreten.
HTTP-Rückgabe-Code: 200
Im Folgenden finden Sie Debugging-Informationen.
Pfad: /de/batch?id=1712&op=do_nojs&op=do
Statustext: parsererror
Antworttext: 2020-05-15 19:41:47 Connection: opening to ssl://asmtp.mail.host***:465, timeout=30, options=array()
2020-05-15 19:41:47 Connection: opened
2020-05-15 19:41:47 SMTP INBOUND: "220 asmtp012.mail.hos*** ESMTP Exim 4.92.3 Fri, 15 May 2020 21:41:47 +0200"
2020-05-15 19:41:47 SERVER -> CLIENT: 220 asmtp012.mail.hos*** ESMTP Exim 4.92.3 Fri, 15 May 2020 21:41:47 +0200
2020-05-15 19:41:47 CLIENT -> SERVER: EHLO www.istdp.ch
2020-05-15 19:41:47 SMTP INBOUND: "250-asmtp012.mail.hostpoint.ch Hello s32.server.h*** [2a00:d70:0:b::1:20]"
2020-05-15 19:41:47 SMTP INBOUND: "250-SIZE 52428800"
2020-05-15 19:41:47 SMTP INBOUND: "250-8BITMIME"
2020-05-15 19:41:47 SMTP INBOUND: "250-PIPELINING"
2020-05-15 19:41:47 SMTP INBOUND: "250-AUTH PLAIN LOGIN"
2020-05-15 19:41:47 SMTP INBOUND: "250-STARTTLS"
2020-05-15 19:41:47 SMTP INBOUND: "250 HELP"
2020-05-15 19:41:47 SERVER -> CLIENT: 250-asmtp012.mail.host*** Hello s32.server.hostp*** [2a00:d70:0:b::1:20]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2020-05-15 19:41:47 Auth method requested: UNSPECIFIED
2020-05-15 19:41:47 Auth methods available on the server: PLAIN,LOGIN
2020-05-15 19:41:47 Requested auth method not available:
2020-05-15 19:41:47 Auth method selected: LOGIN
2020-05-15 19:41:47 CLIENT -> SERVER: AUTH LOGIN
2020-05-15 19:41:47 SMTP INBOUND: "334 VXNlcm5hbWU6"
2020-05-15 19:41:47 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-05-15 19:41:47 CLIENT -> SERVER: c2VrcmV0YXJpYXRAaXN0ZHAuY2g=
2020-05-15 19:41:47 SMTP INBOUND: "334 UGFzc3dvcmQ6"
2020-05-15 19:41:47 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-05-15 19:41:47 CLIENT -> SERVER: RnFFM3ZGajhGYQ==
2020-05-15 19:41:47 SMTP INBOUND: "235 Authentication succeeded"
2020-05-15 19:41:47 SERVER -> CLIENT: 235 Authentication succeeded
2020-05-15 19:41:47 CLIENT -> SERVER: MAIL FROM:
2020-05-15 19:41:47 SMTP INBOUND: "250 OK"
2020-05-15 19:41:47 SERVER -> CLIENT: 250 OK
2020-05-15 19:41:47 CLIENT -> SERVER: RCPT TO:
2020-05-15 19:41:47 SMTP INBOUND: "250 Accepted"
2020-05-15 19:41:47 SERVER -> CLIENT: 250 Accepted
2020-05-15 19:41:47 CLIENT -> SERVER: DATA
2020-05-15 19:41:47 SMTP INBOUND: "354 Enter message, ending with "." on a line by itself"
2020-05-15 19:41:47 SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself
2020-05-15 19:41:47 CLIENT -> SERVER: Date: Fri, 15 May 2020 21:41:47 +0200

aiphes’s picture

Hi.
Face off this issue with 8.x-1.0-beta7 and D884.
Is it related to Drupal or/and module version ?

On other website with 8.x-1.0-rc1 + D885 : no message but messages doesn't send.
Test with D885 + rc2 : ?

The test message work in both cases but the D884 display the error message on status report:
SMTP module is enabled, turned on, but SmtpConnect() threw exception SMTP Error: Could not authenticate.
So who say right ? Status report or test message ?

aiphes’s picture

The error disappear after update the module to rc2 + D886:
- Updating drupal/smtp (1.0.0-beta7 => 1.0.0-rc2): Downloading (100%)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bendqh1’s picture