Linux : How to Configure and install SendMail Configuration in Centos OS 7 for Bulk Emailing

Hello All

In this blog, we are going to cover sendmail configuration in centos 7 servers.

 It's typically installed on an email server on a dedicated machine that accepts outgoing email messages and then sends these messages to the defined recipient. 

The overall benefits of using Sendmail are tied to having an internal email server and Another benefit of hosting your own email server is that it can more easily integrate with internal applications

Introduction

Sendmail is an MTA (Mail Transfer Agent) that uses SMTP protocol for sending email in Linux servers flavours like Centos, Ubuntu etc.

In this blog, we are going to see, how install the send mail and configure the relay settings in Centos 7  operation system

Login with root on any centos 7 or above  version of servers and execute the below commands one by one

sudo yum install epel-release




sudo yum install sendmail sendmail-cf m4



vi /etc/mail/sendmail.mc


Before we configuring the above file, we need to understand the important configuration files


  • access: used to allow or deny other systems to use Sendmail for outbound emails.
  • domaintable: used for domain name mapping for Sendmail.
  • local-host-names: used to define an alias for a host.
  • mailertable: used to override routing for particular domains.
  • virtusertable: allowing multiple virtual domains to be hosted on one machine.


open the sendmail.mc  file in any of the editor like VIM, or VI

=========================================================================

Note : 

Commenting/Uncommenting Lines:

To comment a line in the sendmail.mc configuration file, you typically add dnl (short for "delete to new line") at the beginning of the line. This tells Sendmail to treat the line as a comment and ignore it.

To uncomment a line, simply remove the dnl from the beginning of the line.

=========================================================================

define(`SMART_HOST', `smtp.gmail.com')dnl 

i used my office365 smart host called "craftnet-in.mail.protection.outlook.com'" instead of Gmail smart host and add the below lines

define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl 

i used port 25 instead of 587

define(`RELAY_MAILER_ARGS', `TCP $h 25')dnl

define(`ESMTP_MAILER_ARGS', `TCP $h 25')dnl 

Uncomment the below lines:

TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 

 #Add the below lines:

FEATURE(`authinfo', `hash /etc/mail/auth/client-info.db')dnl

FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl

DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnl 

 #Uncomment for Sendmail to listen on port 587

DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl 

 #Uncomment for Sendmail to listen on port 587

DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl 

 #Mention your domain and uncomment

MASQUERADE_AS(`mydomain.com')dnl

sample : MASQUERADE_AS(`localhost')dnl

Save and exit the file.

=========================================================================

we need to assign the appropriate permissions to create an auth directory inside /etc/mail.

sudo mkdir /etc/mail/auth

cd /etc/mail/auth

Create a new file client-info and below auth in the file.

vi client-info

AuthInfo:cloudmonkeys.xyz "U:username" "P:password" "M:PLAIN"

AuthInfo: "U:username" "P:Password" "M:PLAIN

makemap -r hash client-info.db < client-info

Add your relay IP

vi /etc/mail/access

Connect: [your-ip ]  RELAY

 Recompiling Sendmail Configuration

To update the Sendmail configuration, compile the /etc/mail/sendmail.mc file using the m4 macro processor.

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

cp -p /etc/mail/sendmail.cf /etc/mail/submit.cf

After recompiling, restart the service by using the command provided below.

sudo service sendmail restart






Happy Learning 😃

Comments