0

I have created an office 365 admin account with the domain name. I also enable two-step verification in my account at the Security info display in the picture:

office365 auth config

But whenever I am sent a mail using this account that will give me an error like this.

2021-02-10 05:33:32 Auth method requested: UNKNOWN
2021-02-10 05:33:32 Auth methods available on the server: LOGIN,XOAUTH2
2021-02-10 05:33:32 Auth method selected: LOGIN
2021-02-10 05:33:32 CLIENT -> SERVER: AUTH LOGIN
2021-02-10 05:33:32 SMTP -> get_lines(): $data is ""
2021-02-10 05:33:32 SMTP -> get_lines(): $str is  "334 VXNlcm5hbWU6
                                      "
2021-02-10 05:33:32 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2021-02-10 05:33:32 CLIENT -> SERVER: xxx
2021-02-10 05:33:32 SMTP -> get_lines(): $data is ""
2021-02-10 05:33:32 SMTP -> get_lines(): $str is  "334 UGFzc3dvcmQ6
                                      "
2021-02-10 05:33:32 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2021-02-10 05:33:32 CLIENT -> SERVER: xxx
2021-02-10 05:33:37 SMTP -> get_lines(): $data is ""
2021-02-10 05:33:37 SMTP -> get_lines(): $str is  "535 5.7.3 Authentication unsuccessful [PN0PR01CA0004.INDPRD01.PROD.OUTLOOK.COM]
                                      "
2021-02-10 05:33:37 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [PN0PR01CA0004.INDPRD01.PROD.OUTLOOK.COM]
2021-02-10 05:33:37 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [PN0PR01CA0004.INDPRD01.PROD.OUTLOOK.COM]
2021-02-10 05:33:37 SMTP Error: Could not authenticate.
2021-02-10 05:33:37 CLIENT -> SERVER: QUIT
2021-02-10 05:33:38 SMTP -> get_lines(): $data is ""
2021-02-10 05:33:38 SMTP -> get_lines(): $str is  "221 2.0.0 Service closing transmission channel
                                      "
2021-02-10 05:33:38 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2021-02-10 05:33:38 Connection: closed
2021-02-10 05:33:38 SMTP Error: Could not authenticate.
<br />
<b>Fatal error</b>:  Uncaught phpmailerException: SMTP Error: Could not authenticate. in C:\xampp\htdocs\dede\PHPMailer\class.phpmailer.php:1714
Stack trace:
#0 C:\xampp\htdocs\dede\PHPMailer\class.phpmailer.php(1557): PHPMailer-&gt;smtpConnect(Array)
#1 C:\xampp\htdocs\dede\PHPMailer\class.phpmailer.php(1340): PHPMailer-&gt;smtpSend('Date: Wed, 10 F...', 'This is a multi...')
#2 C:\xampp\htdocs\dede\PHPMailer\class.phpmailer.php(1215): PHPMailer-&gt;postSend()
#3 C:\xampp\htdocs\dede\register.php(187): PHPMailer-&gt;send()
#4 {main}

How can I send SMTP Mail using two-step verification? I have also created Two Active users like user1 and user2. if I want to send SMTP mail using this user then what can I do for that?

Synchro
  • 35,538
  • 15
  • 81
  • 104
suchit rana
  • 1
  • 1
  • 1
  • Refer to Office365 docs – I expect you should be able to create an app-specific password for this purpose, or use XOAUTH2. Meanwhile, you should change your password since your debug includes it in an easily-decoded form. – Synchro Feb 10 '21 at 09:04
  • can you share with me some links or references for that? I am created an app-specific password but where it can be used? – suchit rana Feb 10 '21 at 12:46
  • You'll need to look that up. You should be able to use an app-specific password just like any other password in PHPMailer – it makes no difference at the client end. – Synchro Feb 10 '21 at 12:48
  • creating app-specific password then it gives me error like this `Fatal error: Uncaught phpmailerException: SMTP Error: Could not authenticate. in C:\xampp\htdocs\myre-capital\class.phpmailer.php:906 Stack trace: #0 C:\xampp\htdocs\myre-capital\class.phpmailer.php(797): PHPMailer->SmtpConnect() #1 C:\xampp\htdocs\myre-capital\class.phpmailer.php(660): PHPMailer->SmtpSend('Date: Tue, 16 F...', '--b1_f08a5b49ad...') #2 C:\xampp\htdocs\myre-capital\class.phpmailer.php(588): PHPMailer->PostSend() #3 C:\xampp\htdocs\myre-capital\register.php(189): PHPMailer->Send()` – suchit rana Feb 16 '21 at 06:53
  • Again, refer to office365 docs for how you're supposed to use their passwords. One thing that won't help is that you're using a very old version of PHPMailer, which also suggests you're not using composer. [Upgrade!](https://github.com/PHPMailer/PHPMailer) – Synchro Feb 16 '21 at 09:15
  • I am not using laravel. I am using core PHP and I refer to the office 365 docs but sometimes I am very confused about admin user and active user settings. – suchit rana Feb 16 '21 at 11:05
  • Laravel has nothing to do with this. Composer is worth using for even the tiniest of projects. Your question is really about how to manage an office365 account than anything to do with PHP, so I recommend you look into Office365 support areas rather than PHP. – Synchro Feb 16 '21 at 11:19
  • I have one admin account Ex:- abc@xx.onmicrosoft.com and one active user's EX:- info@xxxl.com. in my admin account I have created a two-factor auth with phone number OTP and Microsoft Authenticator. and in my app, I have created a normal app password but when I am using this both account for SMTP mail using PHPmailer they give me an SMTP Error: Could not authenticate but I have entered both account password is correct. can You help me for that? – suchit rana Feb 16 '21 at 12:05
  • PHPMailer can only work with username and password, so if that's not working you need to check what's happening on the server side yourself. It may be that you need to explicitly enable external SMTP access, but I couldn't tell you how. – Synchro Feb 16 '21 at 14:44

1 Answers1

0

In order to use SMTP authentication, Office 365 requires the following settings to be enabled:

Host = "smtp.office365.com"
Port = 587
SMTPAuth = true;
SMTPSecure = "tls";
SMTPAutoTLS = true;

In addition, the value of From must match the value of Username otherwise Microsoft's SMTP servers will reject it.

Second: check to see whether SMTP AUTH is enabled for that mailbox, see https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission

Also: If you must use MFA for this account, then make sure you use an App Password: https://learn.microsoft.com/en-us/azure/active-directory/user-help/multi-factor-authentication-end-user-app-passwords

Joel
  • 135
  • 9