Created
January 23, 2019 14:09
-
-
Save racheats/0632a1d1572b82230e46e5f348ee926e to your computer and use it in GitHub Desktop.
Setup for mailhog installation on ubuntu xenial 16.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $EUID -ne 0 ]]; then | |
echo "Please run as root" | |
exit | |
fi | |
MAILHOG_URL=github.com/mailhog/MailHog | |
MHSENDMAIL_URL=github.com/mailhog/mhsendmail | |
MAILHOG_EXECUTABLE=/usr/local/bin/mailhog | |
MHSENDMAIL_EXECUTABLE=/usr/local/bin/mhsendmail | |
PHPINI_PATH="$( php --ini | grep /php.ini | awk -F: '{print $2}' )" | |
# verify golang installation | |
go version | |
# get mailhog and mailhandler installation | |
go get $MAILHOG_URL && go get $MHSENDMAIL_URL | |
# setup mailhog and mailhandler tobe accessible globally | |
cp $GOPATH/bin/MailHog $MAILHOG_EXECUTABLE && cp $GOPATH/bin/mhsendmail $MHSENDMAIL_EXECUTABLE | |
# set sendmail_path value on php.ini to mailhandler executable | |
sed -i "s/;sendmail_path.*/sendmail_path = /usr/local/bin/mhsendmail /" /etc/php/7.2/cli/php.ini | |
# create mailhog service to invoking on system booting | |
cat <<EOF >/etc/systemd/system/mailhog.service | |
[Unit] | |
Description=Mailhog service | |
[Service] | |
ExecStart=/usr/local/bin/mailhog -api-bind-addr 0.0.0.0:8025 -ui-bind-addr 0.0.0.0:8025 -smtp-bind-addr 127.0.0.1:1025 | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
# start, enable and check mailhog status | |
systemctl start mailhog && systemctl enable mailhog && systemctl status mailhog | |
# test email submission | |
php -r "\$from = \$to = 'your.emailaddress@gmail.com'; \$x = mail(\$to, 'subject'.time(), 'Hello World', 'From: '. \$from); var_dump(\$x);" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
installation mailhog and mailhandler for PHP