User:Paul/sandbox/Configure Postfix to send through local OpenBSD mail server

From UNPM.org Wiki
Jump to navigation Jump to search
Postfix

Outside of OpenBSD, Postfix is among the most popular MTA packages.

Ubuntu 18.04

Ubuntu Server 18.04 is most commonly configured to send mail using postfix, which has an installer that provides most of the configurations automatically. Note that the OpenSMTPD version in the Ubuntu repositories is no longer supported and should not be used.

Install Postfix

Install postfix using the package installer Satellite system option:

 username@hostname:~$ sudo aptitude install postfix

In the install options, select Satellite system. The System mail name should default to the system hostname of hostname.example.com. For the SMTP relay host enter the IP address of the SMTP server on the private network in the format 192.0.2.38.

Configure aliases

 username@hostname:~$ sudo nano /etc/postfix/aliases

Add the administrator email address for system messages to the aliases file:

 root:          username@example.com

Update aliases.db:

 username@hostname:~$ sudo newaliases

Configure TLS support

Configure TLS support for sending email:

 username@hostname:~$ sudo nano /etc/postfix/main.cf

Add to the bottom of the # TLS parameters section:

 smtp_tls_security_level = may

Restart postifx:

 username@hostname:~$ sudo service postfix restart

Send test email

Install mail to test sending mail:

 username@hostname:~$ sudo aptitude install bsd-mailx
 username@hostname:~$ mail root
 Subject: Happy tester mail subject.
 Happy tester mail body.
 
 Bye!

Press Ctrl+D on the empty line after the last line and Enter when Cc: is displayed to send the message.

Verify the email was sent:

username@hostname.com:~$ tail /var/log/mail.log Nov 1 11:09:00 hostname postfix/pickup[18670]: 51F2C61242: uid=1000 from=<username> Nov 1 11:09:00 hostname postfix/cleanup[18698]: 51F2C61242: message-id=<20211101180900.51F2C61242@hostname.example.com> Nov 1 11:09:00 hostname postfix/qmgr[18671]: 51F2C61242: from=<username@hostname.example.com>, size=448, nrcpt=1 (queue active) Nov 1 11:09:00 hostname postfix/cleanup[18698]: 5519761241: message-id=<20211101180900.51F2C61242@hostname.example.com> Nov 1 11:09:00 hostname postfix/qmgr[18671]: 5519761241: from=<username@hostname.example.com>, size=587, nrcpt=1 (queue active) Nov 1 11:09:00 hostname postfix/local[18700]: 51F2C61242: to=<root@hostname.example.com>, orig_to=<root>, relay=local, delay=0.03, delays=0.02/0/0/0.01, dsn=2.0.0, status=sent (forwarded as 5519761241) Nov 1 11:09:00 hostname postfix/qmgr[18671]: 51F2C61242: removed Nov 1 11:09:00 hostname postfix/smtp[18701]: 5519761241: to=<username@example.com>, orig_to=<root>, relay=192.0.2.38[192.0.2.38]:25, delay=0.29, delays=0.01/0.03/0.25/0.01, dsn=2.0.0, status=sent (250 2.0.0 ae6a2b35 Message accepted for delivery) Nov 1 11:09:00 hostname postfix/qmgr[18671]: 5519761241: removed

Verify message was relayed

In the SMTP server, print the last 11 lines of logs:

smtp:~ $ tail -11 /var/log/maillog Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d784e01fff7 smtp connected address=192.0.2.155 host=<unknown> Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d784e01fff7 smtp tls ciphers=TLSv1.3:AEAD-AES256-GCM-SHA384:256 Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d784e01fff7 smtp message msgid=ae6a2b35 size=1568 nrcpt=1 proto=ESMTP Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d784e01fff7 smtp envelope evpid=ae6a2b353e9046c8 from=<username@hostname.example.com> to=<username@example.com> Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d784e01fff7 smtp disconnected reason=quit Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d7bd1681734 mta connecting address=smtp://203.0.113.99:25 host=mail.example.beer Nov 1 11:09:00 smtp smtpd[55041]: a2bc8d7bd1681734 mta connected Nov 1 11:09:01 smtp smtpd[55041]: a2bc8d7bd1681734 mta tls ciphers=TLSv1.3:AEAD-AES256-GCM-SHA384:256 Nov 1 11:09:01 smtp smtpd[55041]: a2bc8d7bd1681734 mta cert-check result="valid" fingerprint="SHA256:bb3424896972e61ec07b1bd5b0943fc2143fd8a8b4123ba15e5e92895212a1cc" Nov 1 11:09:01 smtp smtpd[55041]: a2bc8d7bd1681734 mta delivery evpid=ae6a2b353e9046c8 from=<username@hostname.example.com> to=<username@example.com> rcpt=<-> source="203.0.113.12" relay="203.0.113.99 (mail.example.beer)" delay=1s result="Ok" stat="250 2.0.0 Ok: queued as 680FB5DD30" Nov 1 11:09:11 smtp smtpd[55041]: a2bc8d7bd1681734 mta disconnected reason=quit messages=1

View the message headers in the receiving server, which should include the message being sent from the original server, relayed through the SMTP server, and passing the SPF and DKIM tests.