Office 365 SMTP

Hi there,

Been using Phabricator for like 2 years now.

I need to setup email relay through office 365. But i keep getting SMTP error so i guess i must have setup the jason file wrong somehow.

This is my mailers.json file:

    "key": "Office365SMTP",
    "type": "smtp",
    "options":    {
        "host": "",
         "port": 587,
         "user": "",
         "password": "DDDDDD",
         "message-id": false,
         "protocol" : "tls"

when i run this command i get ok

./bin/config set cluster.mailers --stdin < mailers.json

Reading value from stdin...
Set 'cluster.mailers' in local configuration.

but when i do the send test i errors:

./bin/mail send-test --to --subject "phab says hullo" < /tmp/test
Reading value from stdin...
Set 'cluster.mailers' in local configuration.
root@AAA:/var/www/html/phabricator/phabricator# ^C
root@AAA:/var/www/html/phabricator/phabricator# ./bin/mail send-test --to --subject "phab says hullo" < /tmp/test
Reading message body from stdin...
[2019-07-23 13:53:57] EXCEPTION: (phpmailerException) SMTP Error: Data not accepted. at [<phabricator>/externals/phpmailer/class.phpmailer.php:741]
arcanist(head=stable, ref.master=b87138356a9c, ref.stable=bbbd1502f078), phabricator(head=stable, ref.master=e0fef74be782, ref.stable=d9b41d3a0f87), phutil(head=stable, ref.master=c3fd3a8bb2c3, ref.stable=0d206344cfd3)
  #0 PHPMailer::SmtpSend(string, string) called at [<phabricator>/externals/phpmailer/class.phpmailer.php:576]
  #1 PHPMailer::Send() called at [<phabricator>/src/applications/metamta/adapter/PhabricatorMailSMTPAdapter.php:155]
  #2 PhabricatorMailSMTPAdapter::sendMessage(PhabricatorMailEmailMessage) called at [<phabricator>/src/applications/metamta/storage/PhabricatorMetaMTAMail.php:750]
  #3 PhabricatorMetaMTAMail::sendWithMailers(array) called at [<phabricator>/src/applications/metamta/storage/PhabricatorMetaMTAMail.php:555]
  #4 PhabricatorMetaMTAMail::sendNow() called at [<phabricator>/src/applications/metamta/PhabricatorMetaMTAWorker.php:22]
  #5 PhabricatorMetaMTAWorker::doWork() called at [<phabricator>/src/infrastructure/daemon/workers/PhabricatorWorker.php:124]
  #6 PhabricatorWorker::executeTask() called at [<phabricator>/src/infrastructure/daemon/workers/PhabricatorWorker.php:163]
  #7 PhabricatorWorker::scheduleTask(string, integer, array) called at [<phabricator>/src/applications/metamta/storage/PhabricatorMetaMTAMail.php:526]
  #8 PhabricatorMetaMTAMail::save() called at [<phabricator>/src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php:228]
  #9 PhabricatorMailManagementSendTestWorkflow::execute(PhutilArgumentParser) called at [<phutil>/src/parser/argument/PhutilArgumentParser.php:457]
  #10 PhutilArgumentParser::parseWorkflowsFull(array) called at [<phutil>/src/parser/argument/PhutilArgumentParser.php:349]
  #11 PhutilArgumentParser::parseWorkflows(array) called at [<phabricator>/scripts/mail/manage_mail.php:21]

I note the error says:

SMTP Error: Data not accepted

which i belive is because there is a error in my SMTP settings.

using powershell i tested if relay was working for the office 365 account and that worked fine. so i don’t think it powershell…

but reading the documentation and post I can’t see where i go wrong with this.

I have firewall turned off on the ubuntu box and on the onprem.

Help me obi van kenobi, you are my only hope!

when i do a:
./bin/mail show-outbound --id 11
I get this:

ID: 11
Status: queued
Related PHID:
Message: SMTP Error: Could not connect to SMTP host.

sensitive: 1
cc: []
subject: phab says hullo
mailtags: []
raw-to: [“”]
message.type: email



(This message has no HTML body.)

I changed the email adress

but it clearly said “SMTP Error: Could not connect to smtp host.”
I can telenet to on port 587 with no problem from the server:

root@XXXX:/var/www/html/phabricator/phabricator# telnet 587
Connected to
Escape character is ‘^]’.
220 Microsoft ESMTP MAIL Service ready at Wed, 24 Jul 2019 08:31:08 +0000
ehlo Hello []
250-SIZE 157286400

i don’t get why this isn’t working…

can i see in a log somewhere some details as to why i can’t connect. How its trying to connect or?

If no one can help would it be possible instead to suggest a mail server software to install on the phabricator server to use instead?

preferably something thats easy to setup and works well with Phabricator?

Any experince welcom :slight_smile:

Am i doing something wrong by posting here? I can’t belive no one can help?

I use Office365 via a postfix relay server on localhost. There are some anti-spam restrictions that Office365 enforces whether you are going direct or via a relay. One of those is that it will not allow a different From address than the logged in account, so Phabricator needs to be configured to send from a single address, which is the one you are logging in as.


Thank you so much for sending answering! :slight_smile: i was really stumped on this one.

so you chose to send through postfix? but don’t you still get the problem with the from field being different? or did you setup postfix to relay from a specifik email?

It was a long time ago, so I may be missing some detail, but I think setting Phabricator config options metamta.can-send-as-user to false, and metamta.default-address to the email address for the account used to logon to the SMTP server was what was needed.

I just looked at the postfix config - since the email is sent from the phd local account, to get the envelope from matching the From line, I had to add a rewrite rule in postfix:

smtp_generic_maps = hash:/etc/postfix/generic

And in /etc/postfix/generic, the local address with the mapping to the Office365 address:

phd@localhost.localdomain noreply@my.office365.domain

Then run sudo postmap hash:generic in the /etc/postfix drectory to generate the hashed file.

But this is probably unnecessary if you can configure SMTP directly from Phabricator instead of using the local mailer.

There is a more comprehensive walkthrough of configuring postfix as a relay to Office 365 here: