quickly setup relay/smarthost with smtp auth in postfix mail server

by jagbir on November 16, 2010

When we decided to host our mail with some other provider, the question of configuring our web servers to use that provider to send mail arise. Having CentOS and postfix as mail service in our hosts, we followed these steps to tell local postfix to use other smtp service to send mails.

1. Suppose you have example.com domain, create one separate mail account to be used in your scripts residing on web server for sending mails. As an example, let’s assume we have mailer@example.com with password mailer123 and mail server address as mail.example.com. Here mail.example.com points to provider mail server which is managing our mail infrastructure. Create a password map file which will contain this information:

# vi /etc/postfix/relaypwd
mail.example.com     mailer:mailer123

2. Check that permissions are ok for that file, or you can set them quickly:

# chown root:root /etc/postfix/relaypwd; chmod 600 /etc/postfix/relaypwd

3. Create hash from this password file:

# postmap /etc/postfix/relaypwd

4. Change/add following configs in your main.cf file, remember that these config may exist already so update them with your values or uncomment them:

# vi /etc/postfix/main.cf
relayhost = [mail.example.com]
 
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/relaypwd
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
mailbox_size_limit = 256000000
myorigin = example.com

5. Restart the postfix service to apply changes:

# service postfix restart

6. Your server now should use the configured mail service to send mails, I’ve already posted one article here to test your mail service completely. Please get confirmed before marking it as done.

More related articles:

* Top 5 most useful tools for Linux Admin
* Detect directory changes in Linux
* Setup MySQL Cluster
* Setup multiple MySQL servers in single host
* Recover or reset MySQL/PostgreSQL root password
* Use exim for normal mail, not for secure smtp service

  • Liam

    Hi there
    I have configured this and tested sending with telnet.

    I have a problem when the recipients address is @ the domain name of the server the sending is being rejected because postfix thinks that it should deliver locally. Here is the error from the maillog:

    Recipient address rejected: User unknown in local recipient table;

    Any ideas how I can make postfix ignore sending mail locally?

    Liam

  • Pingback: güvenli host,kaliteli host,ucuz hosting

Previous post:

Next post: