Install using yum

yum install postfix dovecot libgsasl-devel

Edit Dovecot configure

1. config dovecot.conf

vim /etc/dovecot/dovecot.conf


add/uncomment these

protocols = imap pop3
mail_location = maildir:~/Maildir
listen = *

2. config 10-mater.conf

vim /etc/dovecot/conf.d/10-master.conf


add these lines into service auth {…}

 unix_listener /var/spool/postfix/private/auth {
 mode = 0666
 user = postfix
 group = postfix
}

Config Postfix

vim /etc/postfix/main.cf

Add these lines:

mydomain = XXX.com
myorigin = $mydomain
inet_interfaces = $myhostname, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# mynetworks_style = host
virtual_mailbox_domains = hash:/etc/postfix/virtual
relay_domains = gmail.com, google.com, xxx.com

virtual_alias_maps = hash:/etc/postfix/virtual
home_mailbox = Maildir/

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
# smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks, check_relay_domains
smtpd_recipient_restrictions =
        permit_sasl_authenticated,
        reject_unauth_destination,
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

restart server

/etc/init.d/dovecot restart
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart