Press "Enter" to skip to content

Send mails using Gmail servers in CentOS

On many occasions we need our server to send emails but we do not have it configured to function as an MTA server nor do we have the necessary DNS records configured.

There is an alternative for our server to use Gmail’s SMTP servers as a mail relay.

Then follow the steps:

1- Create a Gmail account. After that you must enable the option “Allow less secure apps to access accounts” under the security options of your account.

2- Install ‘mailx’ on your server:

3- Add the following lines to the “/etc/mail.rc”  file:

4- You can now check if it is working by sending a sample e-mail:

Example: Sending Nagios alerts via e-mail

Now that you can send mails from your server you can now set Nagios config in order to send you an e-mail when an alert is raised.

To do that, you only have to change the $CONTACTEMAIL$  variable on “/usr/local/nagios/etc/objects/commands.cfg” file and replace it by your receiver mail account:

You can test it by forcing an alert notification from the nagios web interface. Go to Services and choose any service, from the Service commands choose “Send custom service notification”:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.