Configuring SENDMAIL for use GMAIL as Relay

Sendmail

To have emails from your linux servers accepted by destination email server you need to send it via trusted smarthost (relay). Google mail relay servers are what we need here. Let’s configure our sendmail for sending mail via gmail relay…

Preparation and installation

Sendmail installation:

Now issue following command to create Gmail authentication file in a folder in which you will add Gmail user name and password.

Next we need to create an authentication file with following contents. You can name it as you like. Just don’t forget to reflect your changes in sendmail’s config.
In this example I have configured it as gmail-idpass:

Create file:

and add following:

[Note: Replace the above with your gmail id and password]

Save and Exit.

In the next step we will need to create a hash map for the above authentication file:

Sendmail Configuration

Now add bellow lines into your /etc/mail/sendmail.mc configuration file. Make sure you add them at end, but right above first “MAILER” definition line:

Example your file may look like this before editing (last few lines)

You need to add the following lines above MAILER(smtp)dnl line

now paste following

Save and exit.

Now your sendmail.mc file will look a like as following after editing (last few lines)

Now we need to re-build sendmail’s configuration. Run following command to do so.

Reload sendmail service:

Now it’s time to test it!

Send email from CLI with sendmail

Now we can send email from a command line using mail command:

This will send email to to-address@example.com

We can track sending status in log:

you should look something like this:

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com