Outbound connections to TCP port 25 (SMTP) are blocked on all CoAI Host servers. The block can't be removed, and trying to get around it is against our Acceptable Use Policy. You can still send email reliably through an authenticated relay.
Use an authenticated SMTP relay
Send mail through a relay you log in to, on port 587 (STARTTLS) or 465 (implicit TLS). Your own email provider's SMTP server works, as do services such as Amazon SES, SendGrid, Mailgun or Postmark. Most relays only accept mail from verified sender domains, so set that up with your provider and publish the SPF and DKIM records they give you.
Many applications have their own SMTP settings. Enter the relay host, port 587, and your username and password there, and you're done. For system mail (cron, alerts, scripts), use one of the options below.
Option 1: Postfix with a relay host
# Debian / Ubuntu
apt install postfix libsasl2-modules
# AlmaLinux / Rocky Linux
dnf install postfix cyrus-sasl-plain
systemctl enable --now postfix
On Debian and Ubuntu, if the installer asks for a configuration type, choose Internet with smarthost. The commands below set everything anyway.
Create /etc/postfix/sasl_passwd with your relay credentials:
[smtp.example.com]:587 your-username:your-password
Protect the file, build the lookup table and point Postfix at the relay:
postmap /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd*
postconf -e "relayhost = [smtp.example.com]:587" \
"smtp_sasl_auth_enable = yes" \
"smtp_sasl_security_options = noanonymous" \
"smtp_sasl_password_maps = $(postconf -h default_database_type):/etc/postfix/sasl_passwd" \
"smtp_tls_security_level = encrypt"
systemctl restart postfix
For port 465, use [smtp.example.com]:465 in both places and also set smtp_tls_wrappermode = yes. Send a test message and check the log for status=sent:
printf "Subject: Test\n\nIt works.\n" | sendmail -f [email protected] [email protected]
journalctl -t postfix/smtp -n 20
Option 2: msmtp for scripts and cron
msmtp hands each message straight to your relay, with no mail server running on your machine.
# Debian / Ubuntu (msmtp-mta provides the sendmail command)
apt install msmtp msmtp-mta
# AlmaLinux / Rocky Linux (requires the EPEL repository: dnf install epel-release)
dnf install msmtp
Create /etc/msmtprc, then run chmod 600 /etc/msmtprc:
defaults
auth on
tls on
syslog on
account relay
host smtp.example.com
port 587
from [email protected]
user your-username
password your-password
account default : relay
For port 465, add tls_starttls off. Test it:
printf "Subject: Test\n\nHello from msmtp.\n" | msmtp [email protected]