Skip to content

Instantly share code, notes, and snippets.

@blakethepatton
Last active November 7, 2023 09:37
Show Gist options
  • Save blakethepatton/7928abb131593fd192606b681ee47b2b to your computer and use it in GitHub Desktop.
Save blakethepatton/7928abb131593fd192606b681ee47b2b to your computer and use it in GitHub Desktop.
Getting Mailhog running on a dev server (nginx, letsencrypt, ssl, ubuntu)

Get it running as a service

wget https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64

mv MailHog_linux_amd64 mailhog

chmod +x mailhog

sudo vi /etc/systemd/system/mailhog.service

[Unit]
Description=MailHog service

[Service]
ExecStart=/usr/local/bin/mailhog

[Install]
WantedBy=multi-user.target

esc :wq

sudo systemctl start mailhog

sudo systemctl enable mailhog

We've got it installed on the server, set up as a service and registered to start with the system

Add it to nginx

sudo vi /etc/nginx/sites-available/default

server {
        server_name mail.your.domain;
        listen 80;
        listen [::]:80;

        location / {
                proxy_pass      http://localhost:8025;
                proxy_set_header    Host             $host;
                proxy_set_header    X-Real-IP        $remote_addr;
                proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header    X-Client-Verify  SUCCESS;
                proxy_set_header    X-Client-DN      $ssl_client_s_dn;
                proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
                proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
                proxy_read_timeout 1800;
                proxy_connect_timeout 1800;
                chunked_transfer_encoding on;
                proxy_set_header X-NginX-Proxy true;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_http_version 1.1;
                proxy_redirect off;
                proxy_buffering off;
        }
}

sudo nginx -t

sudo service nginx reload

sudo certbot --nginx

Install postfix(or your more favorite sendmail client) if it's not already installed

sudo apt-get install postfix

choose the smarthost option

localhost:1025 is the smtp server you want to point to

Update your php-fpm config (optional)

sudo vi /etc/php/7.2/fpm/php.ini

type /sendmail_path

sendmail_path = /usr/sbin/sendmail -t -i

esc :wq

sudo service php7.2-fpm restart

send a test email in php, see it show up in mailhog on the domain you set up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment