In this page we will only do the sendmail configuration to use third party SMTP service. Before starting to configure any application it is a best practice to configure a hostname of the machine according to their service or any to identify as a resource in your environment. Follow this link to change hostname.
$ sudo dnf install sendmail procmail cyrus-sasl sendmail-cf -y
If already logged-in as root user then use the above command without sudo. To edit the sendmail files we will require root user's privilege. # mkdir /etc/mail/authinfo # chmod 700 /etc/mail/authinfo
# vi /etc/mail/authinfo/smtp-gmail
And add the following content in it. AuthInfo: "U:root" "I:sender@gmail.com" "P:AppPassword"
In the above content AppPassword is created as instructed in step 3 link. # makemap hash /etc/mail/authinfo/smtp-gmail < /etc/mail/authinfo/smtp-gmail
This hash file will use in configuration to authenticate remote SMTP service. Once the hash file is created or update the authentication details file can be remove but if there is any change like change in password then again that authentication file is need to create and update the hasp file with same command. If the hash file is updated in same filename then there is no require to re-build sendmail configuration or restart sendmail service. # vi /etc/aliases
Whenever that user tries to send mail then he can use remote SMTP service. Add below line for root user in aliases file below the line of postmaster: alias. Replace the sender with your GMAIL account Id. root: sender@gmail.com
After edit to apply the changes in aliases.db file run below command. # newaliases
It is always better to keep the require configuration together. Some of the below options are available but those are commented. define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl define(`confAUTH_OPTIONS', `A p')dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl FEATURE(`authinfo',`hash -o /etc/mail/authinfo/smtp-auth.db')dnl m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
In this rebuild process, source file with .MC extension is convert in to sendmail configuration file which ends with .CF extension it can read by sendmail process. To make sendmail configuration file, command m4 can be use. Or run the below shell script which is shipped with sendmail package # /etc/mail/make
# systemctl restart sendmail
$ echo "The only source of knowledge is the experience" | \
mail -s "Test sendmail relay" recipient@gmail.com |