Note: This is not a guide/how to.
Sending periodic cron mails using sendmail listening only on localhost 127.0.0.1:25 via smarthost TLS submission 587 from private server
Shipped sendmail version in base doesn't have SASL enabled which is required for auth so we need to use sendmail from pkg or build it manually from ports with SASL option which will install cyrus-sasl cyrus-sasl-saslauthd. There's no need to be enabled in /etc/rc.conf as we won't accept/listening for any outside connections.
If you don't have valid DNS/rDNS record for that host add it into /etc/hosts otherwise gethostbyaddr(3) will fail to resolve the hostname.
/etc/hosts
check for SASLv2
Check supported AUTH options
comment exposed user using dnl or delete the line. Otherwise we can't masquerade the domain name for that user and the periodic mails will be send as root@host.example.com instead of root@example.com
Forward all e-mails from root to user@example.com
This will create the FQDN .mc and .cf files also will build the aliases database and restart the sendmail.
refer to the /etc/mail/Makefile for detailed info. If you need to rebuild only the aliases.db then you can use newaliases(1)
or send to root
And for the postfix users:
all you need to do is to change
myorigin = $mydomain
For FreeBSD-14.0 the default MTA is DMA. The example configuration is:
/etc/dma/dma.conf
/etc/dma/auth.conf
Send a test message using:
The DMA spooler is in
/var/spool/dma
If you want to delete some stuck queue from the spooler you can delete it's content using:
Sending periodic cron mails using sendmail listening only on localhost 127.0.0.1:25 via smarthost TLS submission 587 from private server
Shipped sendmail version in base doesn't have SASL enabled which is required for auth so we need to use sendmail from pkg or build it manually from ports with SASL option which will install cyrus-sasl cyrus-sasl-saslauthd. There's no need to be enabled in /etc/rc.conf as we won't accept/listening for any outside connections.
If you don't have valid DNS/rDNS record for that host add it into /etc/hosts otherwise gethostbyaddr(3) will fail to resolve the hostname.
/etc/hosts
AAA.BBB.CCC.DDD hostname.example.com hostname
pkg install sendmail ca_root_nss
cp /usr/local/etc/mail/mailer.conf.sendmail /usr/local/etc/mail/mailer.conf
openssl dhparam -out /etc/mail/certs/dh.param 4096
service sendmail restart
check for SASLv2
sendmail -d0.1 -bv root
Check supported AUTH options
openssl s_client -connect smtp.example.com:587 -starttls smtp
ehlo test
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
quit
ee /etc/mail/authinfo
Code:
AuthInfo: "U:root" "I:user@example.com" "P:PASSWORD"
makemap hash authinfo < authinfo
chmod 600 authinfo authinfo.db
cp /usr/share/sendmail/cf/domain/generic.m4 /usr/share/sendmail/cf/domain/mydomain.m4
ee /usr/share/sendmail/cf/domain/mydomain.m4
comment exposed user using dnl or delete the line. Otherwise we can't masquerade the domain name for that user and the periodic mails will be send as root@host.example.com instead of root@example.com
dnl EXPOSED_USER(`root')
ee /etc/mail/freebsd.mc
note: MASQUERADE_DOMAIN should be (canonical domain name) $j reported fromDOMAIN(mydomain)
define(`SMART_HOST',`[smtp.example.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl
MASQUERADE_DOMAIN(`host.example.com')dnl
MASQUERADE_AS(`example.com')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`masquerade_entire_domain')dnl
sendmail -d0.1 -bv root
this is the FQDN which we want to rename during outgoing e-mails.Forward all e-mails from root to user@example.com
ee /etc/mail/alises
cd /etc/mail
make
make install
make aliases
service sendmail restart
This will create the FQDN .mc and .cf files also will build the aliases database and restart the sendmail.
refer to the /etc/mail/Makefile for detailed info. If you need to rebuild only the aliases.db then you can use newaliases(1)
echo "test mail" | mail -s "test mail" user@example.com
or send to root
echo "test mail" | mail -s "test mail" root
And for the postfix users:
all you need to do is to change
myorigin = $mydomain
For FreeBSD-14.0 the default MTA is DMA. The example configuration is:
/etc/dma/dma.conf
Note: If your FQDN on your server match the domain name of the smarthost then use "NULLCLIENT" option in dma.confSMARTHOST smtp.example.com
PORT 587
ALIASES /etc/aliases
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
MAILNAME host.domain.com
MASQUERADE root@example.com
/etc/dma/auth.conf
Code:
user@example.com|smarthost.example.com:password
Send a test message using:
The DMA spooler is in
/var/spool/dma
If you want to delete some stuck queue from the spooler you can delete it's content using:
rm /var/spool/dma/*.*
Last edited: