Sending emails in Symfony via a docker container mail server

Viewed 6219

I'm trying to send emails via a docker container in my symfony app in dev environment.

I have the following docker-compose file :

my-app-mailer:
  image: tvial/docker-mailserver
  container_name: my_app_mailer
  hostname: mail
  domainname: myapp.dev
  ports:
  - "25:25"
  - "143:143"
  - "587:587"
  - "993:993"
  volumes:
  - ./mail/spamassassin:/tmp/spamassassin/
  - ./mail/postfix:/tmp/postfix/

So when I run docker-compose up, my container is well launched, and I can see its logs.

I followed the reccomandations from the official repo of tvial/docker-mailserver

https://hub.docker.com/r/tvial/docker-mailserver/

In my parameters.yml, I have these options

parameters:
    ...
    mailer_transport: smtp
    mailer_host: mail.myapp.dev
    mailer_user: user1@myapp.dev
    mailer_password: user1pass
    ...

But when I send emails via swiftmailer, I can't see any of them arrive :(

I have parametred the delivery_address to mine (so that every mail in dev env are sent to my address).

However, I success to send mail via telnet :

telnet mail.myapp.dev smtp

And I can see the mails arriving.

Has anyone a clue of what i've been missing ?

EDIT

Here is my php code with the email sending (I'm in a command)

$mailer = $this->getContainer()->get('mailer');
$message = new \Swift_Message('subject', 'body');
$message
    ->setFrom('user1@myapp.dev')
    ->setTo('xxxx@xxx.xx')
;

$mailer->send($message);

EDIT 2

This is getting weirder : I success to send mails via the command interface :

php app/console swiftmailer:email:send --from=test@myapp.dev --to=xxx@xxx.xx --subject=s1 --body=b1

but still can't do via my own command :\

1 Answers
Related