Yii2 Mailer: connection refused when trying to connect to smtp.office365.com

Hi.

I’m unable to establish a connection to office365 from my subdomain (api.mydomain.com). I get the following error:


[Swift_TransportException] exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.office365.com [Connection refused #111]

I’m using GoDaddy with Office365 account. The email address works, have it sending and receiving emails from my Android phone.


'components' => [

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',           

            'viewPath' => '@api/mail',

            'useFileTransport' => false,

            'enableSwiftMailerLogging' => true,

            'transport' => [

            	'class' => 'Swift_SmtpTransport',

            	'host' => 'smtp.office365.com',

            	'username' => 'donotreply@domain.com',

            	'password' => 'password',

            	'port' => '587',

            	'encryption' => 'tls',

            ],

        ],

    ],

So, is the error because I’m trying to send the mail from my subdomain? Am I missing something?

Any help would greatly be appreciated. I’m stuck and just can’t get it to work.

The following SO topic seems to apply to your problem.

http://stackoverflow.com/questions/24619871/error-sending-emails-in-symfony-2-connection-refused-111