symfony / swiftmailer-bundle

Symfony Swiftmailer Bundle
https://symfony.com/swiftmailer-bundle
MIT License
1.56k stars 151 forks source link

decode reserved chars in password and username in url configuration option #234

Closed eeemarv closed 5 years ago

eeemarv commented 6 years ago

In the "url" configuration option, when username and password are passed in the standard way:

url: smtp://USERNAME:PASSWORD@email-host.com:587?encryption=tls

They are not url decoded. So they can't contain any reserved chars like ! * ' ( ) ; : @ & = + $ , / ?# | (RFC 3986)

However, when username and password are passed as query parameters, they are url decoded as part of the parse_str function.

url: smtp://email-host.com:587?encryption=tls&username=USERNAME&password=PASSWORD

It might also be good to mention in the documentation that when using the url configuration option, the username and password should be url encoded (percent-encoding) when they contain reserved chars. I'm using AWS SES and my password contains a slash (/) and a plus sign (+). It doesn't work when used raw either in the query (the + becomes a space) or in the standard way (the parse_url function returns false because of the slash).

arnoldrch commented 6 years ago

I have this problem to when the apps try to send the email always return: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username

This problem happen on Symfony 4 and swiftmailer bundle 3.2

modnarlluf commented 6 years ago

I got the same problem. As a temporary fix, I use the following configuration for swiftmailer.yaml:

swiftmailer:
    transport: '%env(MAILER_TRANSPORT)%'
    host: '%env(MAILER_HOST)%'
    port: '%env(MAILER_PORT)%'
    encryption: '%env(MAILER_ENCRYPTION)%'
    auth_mode: '%env(MAILER_AUTH_MODE)%'
    username: '%env(MAILER_USERNAME)%'
    password: '%env(MAILER_PASSWORD)%'
    spool: { type: 'memory' }

Less sexy.

eeemarv commented 6 years ago

@modnarlluf I use the MAILER_URL with url (percent) encoded query parameters for now. This issue is about that this is not possible with USERNAME and PASSWORD in their normal location:

smtp://USERNAME:PASSWORD@email-host.com:587?encryption=tls

This form is also used for configuring Doctrine: https://symfony.com/doc/current/doctrine.html#configuring-the-database

naderman commented 5 years ago

Duplicate of this issue: https://github.com/symfony/swiftmailer-bundle/issues/270