Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 Swiftmailer + Amazon SES: Failed to authenticate on SMTP server with username "XXXXXXXXXXXXXXXX" using 2 possible authenticators

I know this question have been asked before but any of the given responses read have become into a solution for this scenario with Symfony2 + Swiftmailer + Amazon SES.

I setup Amazon SES account details for Swiftmailer in Symfony2, all the information is correct, user name and password. However by some weird reason I don't catch up Symfony2 Swiftmailer drops me this error while sending the email.

Failed to authenticate on SMTP server with username "XXXXXXXXXXXXXXXX" using 2 possible authenticators

This is what I got in config.yml

#app/config/config.yml

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    port:      "%mailer_port%"
    encryption: "%encryption%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"

And parameters.yml

#app/config/parameters.yml

parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: null
    database_name: mydatabase
    database_user: dbuser
    database_password: dbpass
    mailer_transport: smtp
    mailer_host: email-smtp.us-east-1.amazonaws.com
    mailer_port: 587
    encryption: tls
    mailer_user: XXXXXXXXXXXXXXXX
    mailer_password: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    mailer_from: [email protected]
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt
    debug_toolbar: true
    debug_redirects: false
    use_assetic_controller: true

Placing a Gmail smtp details instead Amazon SES works just fine and sends email rightly. But with Amazon SES configuration it doesn't. I repeat, user name is correct, it works with Amazon SES Mailer library, but does not do it with Symfony integrated Swiftmailer.

Some thoughts?

like image 211
emorales Avatar asked Jul 07 '14 15:07

emorales


2 Answers

I know this is an old question, but I just want to add something, since I passed the last 3 hours trying to solve this exact problem.

From Symfony V4.0, the configuration of Swift Mailer is done like this, trough enviroment variables:

MAILER_URL=smtp://email-smtp.us-east-1.amazonaws.com:587?encryption=tls&username=YOUR_SES_USERNAME&password=YOUR_SES_PASSWORD

As showed here.

The problem is that is an URL, so that means that if the string has any special characters, they need to be encoded, in this case the password had a plus on it eg. :

AKD23$ADADADJJ$123123LKIOU8jUIJ8j+9IJHJW8JNN4nnn2

This refused to work, until I changed to this:

AKD23$ADADADJJ$123123LKIOU8jUIJ8j%2B9IJHJW8JNN4nnn2

This completely solved the problem once and for all.

like image 173
Tio Avatar answered Nov 07 '22 23:11

Tio


All your configuration parameters I think are just fine like in the Symfony2 documentation states http://symfony.com/doc/current/cookbook/email/cloud.html

If with the Amazon SES Mailer library which is part of the AWS SDK it works, then check if you are using the right credentials for the SMTP solution with Swiftmailer in Symfony2.

When you use the AWS SDK you use the AWS access keys to access the SES API and be able to send email using the Amazon SES Mailer included in that SDK.

When you use another library like Swiftmailer you'll be sending email via the Amazon SES SMTP interface it requires the SMTP credentials, not the AWS access keys.

This SMTP credentials are generated from the SMTP settings in the SES console and those are the right ones that should be used when using SMTP to send email with amazon SES.

Check this documentation http://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-credentials.html

like image 27
elvismdev Avatar answered Nov 07 '22 23:11

elvismdev