0

I have a problem with my application. I try to send email using outlook smtp. But it doesn't work.

Before I used gmail in the configuration and it worked perfectly :). And for a customer I tried to make it work with outlook. So I try to change the parameter Mailer_url in the .env file. After I made the change I tried the command to test:

php bin/console swiftmailer:email:send

It worked fine because I received the email. But when I try via my application it doesn't work.

This is my configuration:

MAILER_URL=smtp://smtp.office365.com:587?encryption=tls&auth_mode=login&username=myaccount@outlook.fr&password=mypassword

Someone have an idea ? Because I don't know why I can send email by command but not by my application. Thank in advance for help :).

Rex5
  • 771
  • 9
  • 23
Arendelle
  • 117
  • 1
  • 10
  • You might want to URL Encode your configuration URL. Some characters may corrupt it. In example if your password contains special characters, such as `#` (your email contains a `@`) – Cid Jun 24 '19 at 13:05
  • Thank for your answer :). How can I Encode my configuration ? – Arendelle Jun 24 '19 at 13:13
  • Could have been faster to type this in your favorite engine than asking there. You can write a script that does that for you, using [`urlencode()`](https://www.php.net/manual/en/function.urlencode.php) in example – Cid Jun 24 '19 at 13:20
  • See [this](https://stackoverflow.com/questions/48915515/symfony-4-swiftmailer-gmail-email-not-sent) – Cid Jun 24 '19 at 13:21
  • It's really strange because my URL is encoded in the swiftmailer.yml if I'm not wrong: `swiftmailer: url: '%env(MAILER_URL)%' spool: { type: 'memory' }` – Arendelle Jun 24 '19 at 13:40
  • Sorry for the double post I try to put information in the swiftmailer.yml `swiftmailer: transport: smtp username: myaccount@outlook.fr password: mypassword host: smtp.office365.com port: 587 encryption: tls auth-mode: login spool: { type: 'memory' }` And set `MAILER_URL=null://localhost` in the `.env` file but always the same problem – Arendelle Jun 24 '19 at 15:19
  • And I try to encode my Mailer_URL but it doesn't work too. Someone have already work with outlook and swiftmailer ? – Arendelle Jun 24 '19 at 15:54
  • What part of the url are you encoding ? The whole part or the values of `username` and `password` ? – Cid Jun 25 '19 at 08:05
  • I suggest you to use the configuration file, like in [this answer](https://stackoverflow.com/a/49137663/8398549). On production, you don't want to use the `.env` file, for security reasons – Cid Jun 25 '19 at 08:07
  • I encode juste username because the password it's not necessary. But there is something I don't understand for gmail I didn't have to encode the url and it worked fine. I already try with the swiftmailer.yml file but the same result. – Arendelle Jun 25 '19 at 08:08
  • Did you clear the cache after doing changes ? – Cid Jun 25 '19 at 08:10
  • Yes everytime I change configuration in the `.env` file or swiftmailer.yml. – Arendelle Jun 25 '19 at 08:12

0 Answers0