Dovecot/Postfix Email Server setup with Gmail Relay

I have been struggling to get an email server setup and working by following many guides online. Here is how I got it working. I had to use Gmail as an relayhost to actually send the email from the server because my ISP blocks me from sending mail on port 25 and doesn’t allow me to relay mail through their servers because I’m using me@mydomain.com instead of me@isp.com)

Software: postfix and dovecot
Operating System: CentOS and Archlinux
(CentOS users need to install cyrus-sasl-plain also )

SASL Configuration

Modify or create: /usr/lib/sasl2/smtpd.conf

pwcheck_method:saslauthd
saslauthd_path: /var/run/saslauthd/mux
SASLAUTHD_OPTS=”${SASLAUTH_MECH} -a pam”
mech_list: plain login
log_level: 7

Dovecot Configuration

Copy the dovecot configuration files :

# cp /usr/share/doc/dovecot/example-config/* /etc/dovecot/

Modify /etc/dovecot/dovecot.conf:

protocols = imap

Modify: /etc/dovecot/conf.d/10-auth.conf :

disable_plaintext_auth = no

Modify: /etc/dovecot/conf.d/10-mail.conf :

mail_location = maildir:~/Maildir

Create or Modify: /etc/pam.d/dovecot

auth required pam_unix.so nullok
account required pam_unix.so

Postfix Configuration

Modify /etc/postfix/main.cf:

myhostname = rusher81572.com
mydomain = rusher81572.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
relayhost = [smtp.gmail.com]:587
home_mailbox = Maildir/
smtp_use_tls=yes
smtp_sasl_auth_enable = yes

smtpd_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/password

smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_security_options =
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,check_relay_domains

Create /etc/postfix/password:

[smtp.gmail.com]:587 username:password

#postmap /etc/postfix/password

#systemctl start postfix