Projekt

Allgemein

Profil

Aktionen

Setting up Postfix to send mails via external mail-account

Preliminary note

See also:

A typical email scenario: you're a developer, and you've got a development Linux box at home. You need to be able to send emails from your code or cron jobs, but you're too lazy to set up a full fledged email server on your LAN. Or you just want to use an email account provided by Google Apps, Yahoo, your ISP or in our case a iRedMail-installation.

Install postfix

Should be preinstalled, as it is the default mail-handler with CentOS

dnf install postfix cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-plain

configure postfix

vim /etc/postfix/main.cf
# line ~118...
myorigin = example.com
# Set this to your email provider's smtp server.
# A lot of ISP's (ie. Cox) block the default port 25
# for home users to prevent spamming.  So we'll use port 587
# line ~339...
relayhost = mail.example.com:587

# add at end of file...
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtp_use_tls = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes

# optional: necessary if email provider uses load balancing and
# forwards emails to another smtp server
# for delivery (ie: smtp.yahoo.com --> smtp.phx.1.yahoo.com)
smtp_cname_overrides_servername = no

# optional: necessary if email provider
# requires passwords sent in clear text
smtp_sasl_security_options = noanonymous

canonical_maps = hash:/etc/postfix/canonical

additionally we need to know the server and email-address as well as the password to use

vim /etc/postfix/sasl_passwd

mail.example.com:587     mailadr@example.com:password

The above server hostname and port must exactly match the value for "relayhost" in /etc/postfix/main.cf.

Generate a postfix lookup table from the previous file

postmap hash:/etc/postfix/sasl_passwd

Test the lookup table, if all is good then the following will return the specified username:password

postmap -q mail.example.com:587 /etc/postfix/sasl_passwd

next is to bind the local username to the email-address. You may also have a look into /etc/aliases and check who's mail are sent to whom.

vim /etc/postfix/canonical

root     mailadr@example.com

The above email-address must exactly match the email-address in sasl_passwd.

Generate a postfix lookup table from the previous file

postmap hash:/etc/postfix/canonical

Make sure that sasl_passwd and sasl_passwd.db files are readable/writeable only by root

chmod 600 /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd.db

Add postfix to be started at boot

systemctl enable postfix

Test postfix

Fire up Postfix

systemctl start postfix

Test it out using sendmail alias from the command prompt

sendmail email@any.com
Postfix is good to go.
.

Von Jeremias Keihsler vor 9 Monaten aktualisiert · 1 Revisionen