Hello, has anyone found a solution to this problem?I can get it to work at all.

Web hosting at Bluehost and using Office365 for emails for many years working without a problem.
Recently I installed osTicket which is amazing (thanks developers), but I can't get it to play nice with Office365. I thought given how popular Office365 is, it would be fairly straightforward. I've searched everywhere with no luck, unless I missed something late one night. I hope someone can help.

Server Information
osTicket Version v1.14.1 (f1e9e88) — Up to date
Web Server Software Apache
MySQL Version 5.6.41
PHP Version 5.6.40

These are the errors I get trying different hostnames that I've found on the forum

smtp.office365.com
authentication failure [SMTP: STARTTLS failed (code: 220, response: TLS go ahead)]

ssl://smtp.office365.com
Failed to connect to ssl://smtp.office365.com:587 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.office365.com:587 (Unknown error) (code: -1, response: )]

tsl://smtp.office365.com
Failed to connect to tls://smtp.office365.com:587 [SMTP: Failed to connect socket: fsockopen(): unable to connect to tls://smtp.office365.com:587 (Unknown error) (code: -1, response: )]

I tried this patch which actually started sending emails when I disabled SMTP. But they go to junk which isn't very professional and it could possibly stop working at anypoint because it's unsecure.
https://stackoverflow.com/questions/39653578/osticket-and-office365-smtp-authentication-failure/39791653#39791653

I used mxtoolbox.com to find the hostname that ends with .mail.protection.outlook.com
Could not get SSL to work, but did get SMTP working without authentication.

4 days later

@emoreno double check your logs and Default MTA setting. When I disabled authentication, it seemed to accept the settings (even though my server requires authentication), but in fact it was logging and error and defaulting the use PHP mail function. What ended up working for me is the following:

1) Update* osTicket's mail class at /include/pear/Net/SMTP.php changing line 176: $this->socket_options =$socket_options; to $this->socket_options = array('ssl' => array('verify_peer_name' => false));

2) Add the required emails to Cpanel with the same password as in Office365.

3) Use http://www.mail-tester.com/ to test for errors (which led me to fix the following deliverability issues)

      A) Edit the domain SPF record

      B) Add a dmarc TXT record to the domain

Replies by my Agents in the UI go to junk. I'm hoping the SPF record hasn't been updated yet and when it does it will solve the problem.

    welltecnologia this worked for my Office365 mail setup. If you host your own exchange servers, you may have other settings that need to be adjusted.

      harbpaul This problem has been going on for years ...
      To this day, they have not found a solution.

      Impressive....

      I've tried Gmail, nothing works on that ...

      I have been struggling with this problem for 3 years ....

      @welltecnologia I know gmail can be tricky, it gave me a headache on another system. Since you have been working on this for so long, I'm sure you Enabled Less Secure Apps in your Gmail Settings? Another issue I faced was communication between the Web Host and Office365, they use the same ports and the web host didn't allow SMTP traffic on those ports. That's why I created those emails in my Cpanel to send from the webhost.

      3 months later
      7 months later

      This patch can solve the issue:

      diff -ru osticket.orig/include/pear/Net/SMTP.php osticket.fixed/include/pear/Net/SMTP.php
      --- osticket.orig/include/pear/Net/SMTP.php	2020-12-07 19:23:52.000000000 +0100
      +++ osticket.fixed/include/pear/Net/SMTP.php	2021-02-13 09:58:08.821455158 +0100
      @@ -569,7 +569,7 @@
                * STARTTLS extension, and aren't already connected over a secure
                * (SSL) socket connection. */
               if ($tls && version_compare(PHP_VERSION, '5.1.0', '>=')
      -            && extension_loaded('openssl') && isset($this->esmtp['STARTTLS'])
      +            && extension_loaded('openssl') && $this->esmtp['STARTTLS']
                   && strncasecmp($this->host, 'ssl://', 6) !== 0
               ) {
                   /* Start the TLS connection attempt. */

      Regards,
      Anthony Ananich
      https colon slash slash ananich dot pro

        17 days later

        anthony1 Hi Anthony, i tried to comment line with -- and add other line, bu the problem for me persist. I ve used a PHP 7.4.13 and IIS with Windows Server 2019.
        May you help me?

        6 months later

        /include/pear/Net/SMTP.php

        Line 176: Replace $this->socket_options = $socket_options; TO
        $this->_socket_options = array('ssl' => array('verify_peer_name' => false));

        Line 572: Replace && extension_loaded('openssl') && isset($this->esmtp['STARTTLS']) TO
        && extension_loaded('openssl') && $this->esmtp['STARTTLS']

        All problem solved for my case
        OSTICKET: 1.15.3.1
        PHP: v7.3.25

        Write a Reply...