After you’ve set up your FreeBSD box, having the box email you for all sorts of reports, cron updates etc is really useful. You don’t have to login to the machine to see them, you can get them in your email. With DragonFly Mail Agent, the setting of such an email system is quick and easy. Here’s the instructions:
Prerequisites #
- Replace nobody@gmail.com with your own email address. Make sure you have two factor authentication on and then you can set up an app password.
- Replace “replace-with-your-app-password” with your gmail app password.
- The following using gmail as your SMTP provider.
- Assumes you’re installing this as root.
Part one - setup DMA #
Setup of DMA for FreeBSD 14.x #
Install DMA #
pkg install dmaBackup original config #
cp /usr/local/etc/dma/dma.conf /usr/local/etc/dma/dma.conf.bakConfigure DMA #
cat > /usr/local/etc/dma/dma.conf << 'EOF'
SMARTHOST smtp.gmail.com
PORT 587
AUTHPATH /usr/local/etc/dma/auth.conf
SECURETRANSFER
STARTTLS
MASQUERADE nobody@gmail.com
EOFSet up authentication #
cat > /usr/local/etc/dma/auth.conf << 'EOF'
nobody@gmail.com|smtp.gmail.com:replace-with-your-app-password
EOFSecure auth file #
chmod 640 /usr/local/etc/dma/auth.conf
chown root:mail /usr/local/etc/dma/auth.confEnable DMA in rc.conf #
sysrc sendmail_enable="NO"
sysrc sendmail_submit_enable="NO"
sysrc sendmail_outbound_enable="NO"
sysrc sendmail_msp_queue_enable="NO"
sysrc dma_enable="YES"Set up mailwrapper #
cat > /etc/mail/mailer.conf << 'EOF'
sendmail /usr/local/libexec/dma
mailq /usr/local/libexec/dma
newaliases /usr/local/libexec/dma
EOFQuick Test #
echo "Test email" | mail -s "Test from FreeBSD" nobody@gmail.comMonitor logs #
tail -f /var/log/maillogSetup of DMA for FreeBSD 15.x #
Notice the path for dma is different, it’s simpler in 15.x.
pkg install dma
cp /etc/dma/dma.conf /etc/dma/dma.conf.bak
cat > /etc/dma/dma.conf << 'EOF'
SMARTHOST smtp.gmail.com
PORT 587
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
MASQUERADE nobody@gmail.com
EOF
cat > /etc/dma/auth.conf << 'EOF'
nobody@gmail.com|smtp.gmail.com:replace-with-your-app-password
EOF
chmod 640 /etc/dma/auth.conf
chown root:mail /etc/dma/auth.conf
sysrc sendmail_enable="NO"
sysrc sendmail_submit_enable="NO"
sysrc sendmail_outbound_enable="NO"
sysrc sendmail_msp_queue_enable="NO"
sysrc dma_enable="YES"
cat > /etc/mail/mailer.conf << 'EOF'
sendmail /usr/libexec/dma
mailq /usr/libexec/dma
newaliases /usr/libexec/dma
EOF
echo "Test email" | mail -s "Test from FreeBSD" nobody@gmail.com
tail -f /var/log/maillogPart two - make cron send emails to you #
# Create /etc/mail/aliases or add root alias
echo "root: nobody@gmail.com" >> /etc/mail/aliases
# Or if you want all mail to go to your Gmail
cat > /etc/mail/aliases << 'EOF'
# Send all system mail to Gmail
root: nobody@gmail.com
EOF
# Then rebuild aliases
newaliases🔵