Pages

Friday, June 14, 2019

Sendmail - Send an email to your Gmail Account

Sendmail is an MTA (mail transfer agent ) server used for transferring email from different hosts. Sendmail uses SMTP ( Simple Mail Transfer Protocol ) protocol. Sendmail is one of the preferred mta used by system admins.

This article helps users for installing sendmail server on centos 7. In this article we will configure sendmail and then Gmail and finally send a mail.

1. Install sendmail using “yum install sendmail sendmail-cf m4 mailx”.
2. Create a directory for storing authentication files
[root@ip-172-31-23-93 ~]# sudo mkdir /etc/mail/authinfo
[root@ip-172-31-23-93 ~]# sudo chmod 700 /etc/mail/authinfo

3. Create an authentication file as smtp-auth and add the contents,
[root@ip-172-31-23-93 mail]# cat authinfo/smtp-auth
AuthInfo: "U:root" "I:jagadesh.manchala@gmail.com" "P:<Password for the mail>"

4. Create a hash map for the authentication file using,
[root@ip-172-31-23-93 ~]# makemap hash /etc/mail/authinfo/smtp-auth < /etc/mail/authinfo/smtp-auth

5. Configure Sendmail with SMART_HOST with below content in /etc/mail/sendmail.mc as below,
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

The above lines should be added before MAILER line.

6. Rebuild sendmail configuration using make command,
[root@ip-172-31-23-93 mail]# make -C /etc/mail
make: Entering directory `/etc/mail'
make: Leaving directory `/etc/mail'

7. Restart the service using “service sendmail restart”

8. Now send a test mail using
[root@ip-172-31-23-93 mail]# echo "Test Email" | mail -s "Subject Here" jagadesh.manchala@gmail.com

While sending mail , if the mail does not come to your account, check for /var/mail/ for recently created log files and check that. SInce iam using gmail, google will not allow to send mail saying suspicious login attempt warning.
Then try to sign in your account there will be a "Suspicious login attempt" warning message at the top of the page. After clicking the warning and authorizing the access, everything works.

We can see the mail in our mail box as,

No comments :

Post a Comment