Configure Postfix to Relay over SMTP+SASL
Install Postfix
Comando |
---|
apt-get install postfix |
The installer will prompt you to select a template for the configuration file. If all e-mail is going to be relayed, select "Satellite"; then enter the SMTP server on the next prompt (e.g. "[smtp.gmail.com]:587").
Note: you need to put brackets around the hostname, like "[example.com]" or "[example.com]:587", since we want to authenticate with the mail server; if we simply used "example.com", then Postfix would look for an MX record and we might end up at an incoming mail server rather than the one that accepts authentication.
Configure Authentication Now, we want Postfix to authenticate with the SMTP server. If you want to relay via your own mail server, an alternative would be to update your mynetworks setting on the target mail server to accept e-mail without authentication (i.e., authorize by IP address). Here, though, we'll use username/password authentication.
Scrivi |
---|
relayhost = [smtp.example.com] |
Scrivi questi dettagli nel file |
smtp_sasl_auth_enable = yes |
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd |
smtp_sasl_security_options = |
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt |
smtp_use_tls = yes |
Here, we are telling Postfix to both use SASL authentication, and also enable TLS for secure communication. We also provide two paths, one for trusted certificate authorities and one for the login credentials.
We now create the /etc/postfx/sasl_passwd file containing login credentials. Replace smtp.example.com with the hostname (without brackets) used in relay host, and also put your actual username and password:
smtp.example.com username:password Update permissions on the file to make it readable only by root user, and create the hash database:
Permessi |
---|
chmod 600 /etc/postfix/sasl_passwd |
postmap /etc/postfix/sasl_passwd |
service postfix reload |
Finallytry sending an e-mail:
mail -s test -r francesco@giberti.net