Symfony Swiftmail with docker mailcatcher

5.4k Views Asked by At

I have a Symfony app (v4.3) running in an docker setup. This setup also has a container for the mailcatcher. No matter how I try to set the MAILER_URL in the .env file no mail shows up in the mailcatcher. If I just the call regular PHP mail() function the mails pops up in the mail catcher. The setup has been used for other projects as well and it worked without a flaw. Only with the Symfony Swiftmailer I can't the mails.

My docker-compose file looks like this:

version: '3'
services:
  #######################################
  # PHP application Docker container
  #######################################
  app:
    container_name: project_app
    build:
      context: docker/web
    networks:
      - default
    volumes:
      - ../project:/project:cached
      - ./etc/httpd/vhost.d:/opt/docker/etc/httpd/vhost.d
    # cap and privileged needed for slowlog
    cap_add:
      - SYS_PTRACE
    privileged: true
    env_file:
      - docker/web/conf/environment.yml
      - docker/web/conf/environment.development.yml
    environment:
      - VIRTUAL_HOST=.project.docker
      - POSTFIX_RELAYHOST=[mail]:1025
  #######################################
  # Mailcatcher
  #######################################
  mail:
    image: schickling/mailcatcher
    container_name: project_mail
    networks:
      - default
    environment:
      - VIRTUAL_HOST=mail.project.docker
      - VIRTUAL_PORT=1080

I pleayed around with the MAILER_URL setting hours but everything failed so far. Hope soembody here has an idea how to set the MAILER_URL.

Thank you

1

There are 1 best solutions below

2
Dmitry Solovov On

According to docker-compose.yml, your MAILER_URL should be:

smtp://project_mail:1025

Double-check if it has the correct value

Then you can view container logs using docker-compose logs -f mail to see if your messages reach the service at all. It will be something like:

==> SMTP: Received message from '<[email protected]>' (619 bytes)

Second: try to restart your containers. Sometimes changes in .env* files are not applied instantly.