Skip to content

Instantly share code, notes, and snippets.

@moisseev
Last active October 28, 2022 09:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisseev/b0dde219d4b4c5f4f1d6ede22bd2dfa4 to your computer and use it in GitHub Desktop.
Save moisseev/b0dde219d4b4c5f4f1d6ede22bd2dfa4 to your computer and use it in GitHub Desktop.
Replacing the default FreeBSD system mailer Sendmail with Postfix using SMTP AUTH, acting as mail client

Replacing the default FreeBSD system mailer Sendmail with Postfix using SMTP AUTH, acting as mail client

Replacing Sendmail with Postfix

# pkg install postfix-sasl1

Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y2

# service sendmail stop

# sysrc postfix_enable="YES"
# sysrc sendmail_enable="NONE"
# echo '# Disable sendmail(8) specific tasks\
daily_clean_hoststat_enable="NO"\
daily_status_mail_rejects_enable="NO"\
daily_status_include_submit_mailq="NO"\
daily_submit_queuerun="NO"\
#' >> /etc/periodic.conf

1: To use SASL authentication Postfix needs be built with Cyrus SASL support.

2: If you skipped this step and Postfix is not already activated in /etc/mail/mailer.conf :

# mv /etc/mail/mailer.conf /etc/mail/mailer.conf.old
# install -m 0644 /usr/local/share/postfix/mailer.conf.postfix /etc/mail/mailer.conf

Configuring SASL authentication in the Postfix SMTP client

Make sure Postfix built with SASL:

# postconf -A
cyrus

Create $config_directory/sasl_passwd:

[smtp.example.com]:submission username:password

# postmap sasl_passwd

Add to main.cf:

# SASL authentication in the Postfix SMTP client
smtp_sasl_auth_enable = yes
relayhost = [smtp.example.com]:submission
smtp_sasl_password_maps = hash:$config_directory/sasl_passwd

# service postfix start

Configuring TLS (optional)

To enable opportunistic TLS add to main.cf:

smtp_tls_security_level = may

Testing

> telnet localhost 25

...

mail from: <user@example.com>

250 2.1.0 Ok

rcpt to: <user1@example1.com>

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

To: <user1@example1.com>

From: <user@example.com>

Subject: Test

Message-Id: <local-part@domain>

Content-Type: text/plain; charset=utf-8

Test

.

250 2.0.0 Ok: queued as 0EA2B53155

<...another mail transaction...>

quit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment