There are many reasons why you may want to do it. I have set it up on my POSTFIX because I have dynamic IP that is banned in most spam databases. I could get mails to my mailbox but could not reply to any as my IP was rejected by most of mail servers. But there is a quick solution.
So what will you need? Not to much. All that you need to set it up is working Postfix server (we will make changes in it's configuration file) and external e-mail account with SMTP access (probably 99% of e-mail account will be ok, for ex. Gmail). So if you want to send emails with external (relay your mail). Here is a quick howto.
Step 1: Edit your configuration file
You will need to make changes in your configuration file (in standard postfix configuration it would be /etc/postfix/main.cf). You need to add at the end of configuration file following lines:
relayhost = smtp.provider.com:25 smtpd_sasl_auth_enable = yes smtpd_sasl_path = smtpd 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
Just make sure that you will edit "relayhost" (in first line of this listing), with your account SMTP address and port number.
Step 2: Generate password file
Postfix have to know your account login and password as most SMTP servers would not allow to rely emails from unauthorized connections. You will need to make a password file "/etc/postfix/sasl_passwd" with similar content:
# The server info must exactly match the value # for "relayhost" in /etc/postfix/main.cf smtp.provider.com:25 username:password
Now you need to generate POSTFIX lookup table (from previous file), with the following command:
$ postmap hash:/etc/postfix/sasl_passwd
You may test it by typing:
$ postmap -q smtp.provider.com:25 /etc/postfix/sasl_passwd
If you will get an output like "username:password" it means that password file has been generated correctly.
You can remove "/etc/postfix/sasl_passwd". POSTFIX will not need it anymore.
It should be working now! Restart your POSTFIX and test it! If you have any problems please make a comment below. I will try to help you.