I am trying to connect to Office 365 with the proper settings, but am getting an "SMTP Error: Could not authenticate", even though the server is responding back with "235 2.7.0 Authentication successful". Any ideas on whether this is a module bug, or something on the Office 365 servers?

SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 DM3PR10CA0023.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 21 Jan 2016 17:36:49 +0000 "
SMTP -> get_lines(): $data is "220 DM3PR10CA0023.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 21 Jan 2016 17:36:49 +0000 "
SMTP -> FROM SERVER:220 DM3PR10CA0023.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 21 Jan 2016 17:36:49 +0000
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] "
SMTP -> get_lines(): $str is "250-SIZE 157286400 "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING "
SMTP -> get_lines(): $str is "250-DSN "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-STARTTLS "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME "
SMTP -> get_lines(): $str is "250-BINARYMIME "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $str is "250 CHUNKING "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250 CHUNKING "
SMTP -> FROM SERVER: 250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 2.0.0 SMTP server ready "
SMTP -> get_lines(): $data is "220 2.0.0 SMTP server ready "
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] "
SMTP -> get_lines(): $str is "250-SIZE 157286400 "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING "
SMTP -> get_lines(): $str is "250-DSN "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-AUTH LOGIN "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME "
SMTP -> get_lines(): $str is "250-BINARYMIME "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $data was "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $str is "250 CHUNKING "
SMTP -> get_lines(): $data is "250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME 250-BINARYMIME 250 CHUNKING "
SMTP -> FROM SERVER: 250-DM3PR10CA0023.outlook.office365.com Hello [2001:4801:7822:101:be76:4eff:fe10:69c6] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 xxxxxxxxx "
SMTP -> get_lines(): $data is "334 xxxxxxxxxxx "
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 xxxxxxxxxxxxx "
SMTP -> get_lines(): $data is "334 xxxxxxxxxxxxxxx "
SMTP -> ERROR: Password not accepted from server:
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "235 2.7.0 Authentication successful target host DB5PR04MB1367.eurprd04.prod.outlook.com "
SMTP -> get_lines(): $data is "235 2.7.0 Authentication successful target host DB5PR04MB1367.eurprd04.prod.outlook.com "
SMTP -> FROM SERVER:235 2.7.0 Authentication successful target host DB5PR04MB1367.eurprd04.prod.outlook.com
SMTP -> ERROR: RSET failed: 235 2.7.0 Authentication successful target host DB5PR04MB1367.eurprd04.prod.outlook.com
SMTP Error: Could not authenticate. 
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chrisnovak created an issue. See original summary.

DamienMcKenna’s picture

Please try the patch in #2287825: Using SMTP Mail with Office365 and see if it helps. It also suggests that there are spaces at the end of the password strings, please confirm that the username and password strings don't include any unwanted spaces (or extra characters) and see if that resolves it.

chrisnovak’s picture

HI Damien,

Thanks for your suggestion. But it looks like the issue reported in https://www.drupal.org/node/2287825 seems to be different than the one reported here. The errors on that issue are " ERROR: Failed to connect to server: Network is unreachable" and " Invalid domain".

The strange thing with this response is that the server is responding that the authentication is successful:
SMTP -> get_lines(): $str is "235 2.7.0 Authentication successful target host DB3PR04MB0682.eurprd04.prod.outlook.com "

so I am not sure why I am getting the "SMTP Error: Could not authenticate" message. Does this mean that there is an issue with the protocol, or there is an actual issue with authentication?

DamienMcKenna’s picture

@chrisnovak: yeah, SMTP debugging is a serious PITA ;) I think all patches that deal with the SMTP connection itself are worth examining.

FYI I marked #2287825 a duplicate because #2656510: Make hostname and HELO configurable expands upon its functionality to make it configurable rather than just hardcoding the values.

timellemeet’s picture

I have the same issue, curiously though it only occurs when I turn on the module in the SMTP config. If I leave it off and send a testmail it works like a charm.

DamienMcKenna’s picture

@timellemeet: That's utterly confusing - the smtp_on variable doesn't seem to do anything anymore, outside of the settings page.

DamienMcKenna’s picture

@timellemeet: Can you please check what the variables "smtp_previous_mail_system" and "mail_system" are set to on your site? That might help explain what's going on.

phonkala’s picture

@chrisnovak @DamienMcKenna @timellemeet Did you ever figure out what the problem is? I'm experiencing exactly the same issue now that my company moved their email accounts to office365 environment.

So basicly if I turn the module off in the config page and send a test mail, everything works fine. When I turn it on and try to do the same, I get error "could not connect to SMTP host" and no mail is sent.

I also tested the mail sending classes in HTML Mail -modules Send Test -page. Using any SmtpMailSystem related class always seems to fail while all other classes send mail correctly.

Edit: Using module version 7.x-2.x-dev but tested other ones too, none seems to help.

DamienMcKenna’s picture

@phonkala: The problem appears to be related to the "from" email address, it has to match the email address of the account you've logged into office365 with.

phonkala’s picture

@DamienMcKenna Sounds a bit weird because I made sure that I am using the same email address in all site settings so can't really understand what the problem would be :/ I'm using "admin@mydomain.com" in every possible email address field and it's also my office365 account name. Tried clearing the From (name) field just to see if it works when you have only set the From email address but it had no effect. Using the same email address in the From (name) field won't help either.

Any idea how it's still possible to send the email when the module is turned off? Does it still login to SMTP server and then somehow succeed in sending the mail or is it even using the SMTP login then at all? Got bit over one month to figure this out or gotta find some other solution to solve the problem, too bad I don't know much about SMTP/email stuff :/

vidichannel’s picture

Using DEV version. Manually entering the hostname in the 'Hostname' and 'HELO' fields worked for me. It says it defaults, but it does not, apparently.

AndrewsizZ’s picture

I have same issue with Office365 ++

AndrewsizZ’s picture

Hey Guys,
Seems like I have found issue.
SMTP object have wrong error handler. When SMTP object have timeout error it return last message from SMTP Server as error, in our case it looks like - "ERROR: RSET failed: 235 2.7.0 Authentication successful target host".

So to fix this issue on module lvl just need to change default 10 sec to 20 sec of timeout settings (check my patch version1)
To make it more flexible we can give user possibility to change timeout settings from admin UI (check my patch version2)

zelph0’s picture

Thanks for the fix. I changed to the 20 sec timeout and it's now working again. Error was "SMTP Error: Could not authenticate." when connecting to the office 365 smtp.

hanoii’s picture

I think @AndrewsizZ was right in catching that the error "2.7.0 Authentication successful target host", which is the one I was getting and similar to others above was because of the low timeout and not the actual filing of the error.

Instead of hardcoding this value into PHPMailer.php, which although seems to be modified anyway by the maintainers, I worked on a configuration option from the drupal side of things.

Please review #2781157-4: Make SMTP timeout configurable, this should help with at least getting an useful error.

webservant316’s picture

webservant316’s picture