Wednesday, August 12, 2020

Setup Postfix MTA to send email on Centos 8 using gmail account

Reference: http://souptonuts.sourceforge.net/postfix_tutorial.html

 # 1. install postfix
[root@thermalite ~]# yum install postfix cyrus-sasl cyrus-sasl-plain
Last metadata expiration check: 2:46:54 ago on Mon 10 Aug 2020 03:13:19 PM EDT.
Package postfix-2:3.3.1-12.el8.x86_64 is already installed.
Package cyrus-sasl-2.1.27-1.el8.x86_64 is already installed.
Package cyrus-sasl-plain-2.1.27-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

# 2. Next, edit the main Postfix configuration file @ /etc/postfix/main.cf to include the following:
[root@thermalite siteconfig]# cat /etc/postfix/main.cf | grep -v "^#" |  sed -e '/^$/d'
compatibility_level = 2
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
mydomain = wezzle.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = wezzle.com, $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
mynetworks = 192.0.0.0/8
relayhost = [smtp.gmail.com]:587
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
mailbox_command = /usr/bin/procmail -a "$EXTENSION"
mailbox_size_limit = 0
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix/samples
readme_directory = /usr/share/doc/postfix/README_FILES
smtpd_tls_cert_file = /etc/ssl/certs/thermalite.crt
smtpd_tls_key_file = /etc/ssl/private/thermalite.key
smtpd_tls_security_level = may
smtp_tls_CApath = /etc/pki/tls/certs
smtp_tls_security_level = may
meta_directory = /etc/postfix
shlib_directory = /usr/lib64/postfix
smtp_use_tls = yes
smtp_tls_loglevel=1
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_path = smtpd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = login, plain
smtp_tls_security_level = verify
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_tls_security_options = noanonymous
message_size_limit = 1024000000
smtpd_tls_auth_only = no
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_sasl_auth_enable = yes
[root@thermalite siteconfig]#


# 3. configure the .mailrc for a user bills
[bills@thermalite ~]$ cat .mailrc
set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=bills.smith@gmail.com
set smtp-auth-password=dfdyhukigkssosbxv
set from="bills.smith@gmail.com"
[malex@thermalite ~]$


# 4. send a test mail_owner
[malex@thermalite ~]$ echo "This is a test email from my server" |\
 /usr/bin/mailx -v -s "Postfix Newsletter Update for `TZ="Asia/Manila" date '+%A, %B %d %Y %H:%M:%S'`" bills.smith@gmail.com


No comments:

Post a Comment