Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to mailpit which supports testing CC and is maintained #31

Open
chrillep opened this issue Feb 6, 2024 · 5 comments
Open

switch to mailpit which supports testing CC and is maintained #31

chrillep opened this issue Feb 6, 2024 · 5 comments

Comments

@chrillep
Copy link

chrillep commented Feb 6, 2024

Background:
I was trying to debug an email that was supose to have a CC aswell. Turns out mailhog wont let you view the cc:ed email.
Long story short, use mailpit instead. :/


Docker images

You can view available Docker images on https://hub.docker.com/r/axllent/mailpit.

A basic example of running Mailpit within Docker:

docker run -d \
--restart unless-stopped \
--name=mailpit \
-p 8025:8025 \
-p 1025:1025 \
axllent/mailpit

You need to ensure you map the correct ports (default Web UI on 8025 and SMTP on 1025).

Setting Mailpit options

View all runtime options (flags & environment variables). Environment variables can be set using the -e flag when starting your docker container, for instance:

docker run -d \
--name=mailpit \
--restart unless-stopped \
-v /path/to/mailpit-data:/data \
-e MP_DATA_FILE=/data/mailpit.db \
-e MP_UI_AUTH_FILE=/data/authfile \
-e TZ=Europe/London \
-p 8025:8025 \
-p 1025:1025 \
axllent/mailpit

Docker compose example

version: '2.4'

services:
  mailpit:
    image: axllent/mailpit
    container_name: mailpit
    restart: always
    volumes:
      - ./data:/data
    ports:
      - 8025:8025
      - 1025:1025
    environment:
      MP_MAX_MESSAGES: 5000
      MP_DATA_FILE: /data/mailpit.db
      MP_SMTP_AUTH_ACCEPT_ANY: 1
      MP_SMTP_AUTH_ALLOW_INSECURE: 1
@chrillep chrillep changed the title witch to mailpit whoch supports cc and is maintained switch to mailpit whoch supports cc and is maintained Feb 6, 2024
@chrillep chrillep changed the title switch to mailpit whoch supports cc and is maintained switch to mailpit which supports cc and is maintained Feb 6, 2024
@chrillep chrillep changed the title switch to mailpit which supports cc and is maintained switch to mailpit which supports testing CC and is maintained Feb 6, 2024
@AaronFeledy
Copy link
Member

AaronFeledy commented Feb 7, 2024

Support for the unmaintained status: mailhog/MailHog#442 (comment) where the maintainer of mailhog also mentions mailpit as an alternative.

@kaszarobert
Copy link

If it helps, this is how we used MailPit since last year in Lando for each site:

In .lando.yml under services add:

  mailpit:
    scanner: false
    api: 3
    type: lando
    services:
      image: axllent/mailpit
      volumes:
        - mailpit:/data
      ports:
        - 8025 # Web UI.
        - 1025 # SMTP.
      environment:
        MP_MAX_MESSAGES: 5000
        MP_DATA_FILE: /data/mailpit.db
        MP_SMTP_AUTH_ACCEPT_ANY: 1
        MP_SMTP_AUTH_ALLOW_INSECURE: 1
      command: '/mailpit'
    volumes:
      mailpit:

Under proxy add (if you'd like localhost domains, then you can also replace .lndo.site with .localhost):

  mailpit:
    - mail.YOURSITENAME.lndo.site:8025

Then lando rebuild -y

In your site set "mailpit" as SMTP server name, "1025" as SMTP server port. You can view sent mails on http://mail.YOURSITENAME.lndo.site URL.

@Epitaffio
Copy link

Thank you @kaszarobert for the snippet, I was banging my head with this for a couple of hours already.

I would still love to see an official recipe for mailpit!

@tormi
Copy link

tormi commented Oct 2, 2024

You also need SMTP setup to start using Mailpit. Drupal Core has a Symfony Mailer component available since version 10.2.

Here's how you can use it with Mailpit:

.lando.yml:

services:
  appserver:
    overrides:
      environment:
        SMTP_ADDRESS: mailpit:1025

I use the SMTP_ADDRESS environment variable locally as it is available in our other environments. Feel free to use plain values in settings.php.

settings.php:

// Symfony Mailer configuration.
// @see: https://www.drupal.org/node/3369935
$config['system.mail']['interface'] = [ 'default' => 'symfony_mailer' ];

// Default SMTP settings.
$smtp_address_parts = explode(':', getenv('SMTP_ADDRESS'));
if (!empty($smtp_address_parts[0]) && !empty($smtp_address_parts[1])) {
  $config['system.mail']['mailer_dsn'] = [
    'scheme' => 'smtp',
    'host' => $smtp_address_parts[0],
    'port' => $smtp_address_parts[1],
  ];
}

Here's the full setup as a PR: https://github.com/wunderio/drupal-project/pull/423/files

@reynoldsalec
Copy link
Member

Nice thanks @tormi.

BTW a little birdie told me that @AaronFeledy might be cooking up a legit mailpit Lando plugin so we can finally mothball this repo. I'm sure he'll post here when there's substantive progress, but wanted to HYPE the possibility :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants