yiisoft / yii2-swiftmailer

Yii 2 swiftmailer extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
116 stars 74 forks source link

Cannot work well with Office365's Starttls #71

Closed InfoButler-LinaLu closed 6 years ago

InfoButler-LinaLu commented 6 years ago

What steps will reproduce the problem?

Send email with other mailbox succeeded already. Recently my user want to switch the mail server to office 365, so changed the mailbox and did some test, failed to send mail.

The config file was set as below:

    'mailer'=>[
            'class'=>'yii\swiftmailer\Mailer',
            'viewPath'=>'@common/mail',
            'useFileTransport'=>false,
            'transport'=>[
                'class'=>'Swift_SmtpTransport',
                'host'=>'smtp.office365.com',
                'username'=>'myusername@domain.com',
                'password'=>'mypassword',
                'port'=>'587',
                'encryption'=>'START/TLS',
            ],
        ],

What's expected?

mail send success

What do you get instead?

Connection could not be established with host smtp.office365.com [php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known #0]

Additional info

Q A
Yii version 2.0.11
Yii SwiftMailer version 2.0.7
SwiftMailer version 5.4.8
PHP version 5.6.11
Operating system Mac OS
cebe commented 6 years ago

'encryption'=>'START/TLS',

according to swiftmailer docs, that should be 'tls', not 'START/TLS'.

https://swiftmailer.symfony.com/docs/sending.html#the-smtp-transport

InfoButler-LinaLu commented 5 years ago

I tried tls, but get the following error: Exception

Swift_TransportException

Failed to authenticate on SMTP server with username "emailaddress@domain.com" using 2 possible authenticators

But I am 100% sure that the email address works good and I can send mail via this address by other mail client. However with my code, it don't work.

cebe commented 5 years ago

maybe this helps: https://stackoverflow.com/questions/6077514/set-authentication-method-in-swiftmailer-4-0-6

In any case this is nothing we can fix in yii2-swiftmailer. Most probably it is a configuration problem, if not, please report it to swiftmailer directly.