One way to transmit mail within a local server is by sending them directly through third party mail servers on the Internet using the SMTP protocol.
Postfix is a free and open-source mail transfer agent (MTA) and available in most Linux distributions (including CentOS 7!).
This guide will outline the basic steps on how to setup Postfix to use your mail-service-provider's SMTP server for outgoing mail. Once configured, all mails from your server will be sent through it.
The following configuration will use 1und1's mail server as an example.
Install the required packages:
$ yum install postfix cyrus-sasl cyrus-sasl-plain
This configuration uses a made-up mail account, and, as already stated above, uses the 1und1 SMTP server to relay outgoing mail.
First and foremost, a password file needs to be created so that Postfix can authenticate to the SMTP server. This is done by creating a file named
/etc/postfix. Replace smtp_user and smtp_passwd with their respective values for your account:
$ echo "smtp.1und1.de smtp_user:smtp_passwd" > /etc/postfix/sasl_passwd
The username in this case would be something like
Now we must convert
/etc/postfix/sasl_passwd into a format that Postfix can read:
$ postmap hash:/etc/postfix/sasl_passwd
The above command will create a file named
sasl_passwd.db in the
And for additional security purposes, only root should have access to the password files:
$ chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db $ chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
After all of those steps are completed, we now configure the main configuration file located under
relayhost and set it to the SMTP server address.
relayhost = smtp.1und1.de:587
Finally add the following lines to the configuration file:
smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes
Keep in mind, that some mail providers force you to use certain security options.
Start or restart Postfix:
$ systemctl start postfix