Tuesday, 28 March 2017

How To Relay Email On A Postfix Server

https://www.howtoforge.com/how-to-relay-email-on-a-postfix-server
https://www.linode.com/docs/email/postfix/postfix-smtp-debian7

1. Prerequisites

I assume that you already have set up a working postfix server and that you have an email account at your ISP which you can access. So you will need to have a login for your IPS's email account.

2. Edit the postfix config

First you need to edit your postfix config...
nano /etc/postfix/main.cf
... and add the following code at the end of your config:
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
smtp_always_send_ehlo = yes
relayhost = smtp.yourisp.com
smtpd_use_tls=yes
smtp_always_send_ehlo = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
#smtp_generic_maps = hash:/etc/postfix/generic
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
mydestination = $myhostname, SMTP, localhost.localdomain, , localhost
relayhost = [smtp.office365.com]:587
mynetworks = 20.10.1.127/32 127.0.0.0/8 20.10.1.6/32 192.168.20.0/24 [::ffff:127.0.0.0]/104 [::1]/128


Of course replace smtp.yourisp.com with the actual smtp server of your ISP. Also SASL must be working. If you followed the perfect howtos for setting up a server as provided by Falko then you don't have to worry about it. Then save and close the file.
If your ISP requires you to use a special port for sending email, then use a line like this instead:
relayhost = [smtp.yourisp.com]:PORT
In one of the cases that I have used this, I had to enter this:
relayhost = [smtpauth.bluewin.ch]:587

3. Edit /etc/postfix/saslpasswd

After having extended the postfix config you'll still need to add the credentials to the /etc/postfix/saslpasswd file, so that you can authorize yourself at your ISP.
nano /etc/postfix/saslpasswd
and then add this:
smtp.yourisp.com     yourlogin:yourpassword
[smtp.office365.com]:587 delivery@gdeasia.com:password
Of course replace yourlogin / yourpassword with the actual username and password provided by your ISP. You don't need to add the port there.

4. Hash /etc/postfix/saslpasswd

Before postfix can use that file, it needs to be hashed by postmap:
postmap /etc/postfix/saslpasswd

5. Restart postfix

Finally you need to restart postfix to use the new config:
/etc/init.d/postfix restart