Sendmail For Outbound Alerts On Red Hat

Orange Mail Sign
 
Last week we discussed implementing Monit on a single instance of Red Hat Enterprise Linux to monitor local services, alert us to their failure via e-mail, and restart them as necessary.  We made the assumption that we’d be able to point to an existing SMTP e-mail server through which we’d mail out those alerts.  But what if we want to eliminate this dependency, and implement an SMTP service directly on the Red Hat server itself, through which Monit (or anything else running on this server) will be able to mail out alerts? Today we’ll walk through this fairly simple addition using Sendmail.

Before we get started, we should mention the following caveats:

  • The Red Hat Enterprise Linux server on which we’ll perform this installation must be registered with the Red Hat Network in order to download the necessary packages.
  • Your server will rely on a valid DNS server that can provide MX record lookups for any recipient.  This is a common feature of DNS generally, and is available in most corporate environments.
  • Assuming you want to send alerts to any recipient outside your company, your server will need to be able to talk out to the Internet via TCP port 25.  Many organizations restrict this via web filter technology.  If you’re setting up Red Hat servers in a corporate environment, then you know who to talk to about Internet filtering.  Finally, many home ISPs prohibit outbound connections on port 25 to try to limit spam from zombie computers.
  • For any command lines in the process shown below, triple-click the line to select it so that you’re sure you’ve got it all, and that it hasn’t wrapped off the right side of the screen.  You should then be able to copy and paste it into a Linux terminal or SSH session.

Let’s get started.

  1. First let’s make sure that our prerequisites are installed.  On a clean install of RHEL 6.5, only one is missing, but lets go ahead and check for all three in a single command…
  2. Install Sendmail…
  3. Build sendmail.cf using m4 macro…
  4. Add the domains from which your server will send mail.  You only need to mention your own domain here, not any domains that you may send mail to.  We’ll edit the configuration file with vim, though you could substitute gedit if you’ve installed the Desktop functionality.  *See footnote at end for suggestions on navigating in vim.
  5. Initially the local-host-names file will contain a single line commented out, as noted by the # sign at the front.  Add the domains from which you’ll be sending e-mail.  We added snnyc.com in our example below…
  6. Once completed, write your changes and quit vim or your editor of choice.  Then let’s (re)start sendmail and set it to launch each time the server boots.

That’s It
We’re done.  Any application or service running on this server can now simply be pointed to localhost for all outbound SMTP e-mail.  In initial testing, we’re able to send Monit alerts both to internal Exchange users and to external Google-hosted mailboxes.  Naturally there is more work to be done if you wish this server to relay outbound mail for other servers, or if you wish to also receive inbound mail.  Those topics are out-of-scope for today’s discussion, but could certainly make for an extended blog post down the road.  Finally, in giving credit where credit is due, Sachin Sharma provided this information and more in his post, from which I borrowed heavily.

* Having opened a file in the vim editor, hit the Insert key immediately.  Use the arrow keys to navigate to where you’d like to add new material, or delete old material.  Type as desired.  When finished, hit the Esc key.  Then type :wq to write your changes and quit.  To abandon vim without saving changes, use :q! instead.

Tweet about this on TwitterShare on Google+Share on LinkedInShare on FacebookShare on RedditEmail this to someone

Speak Your Mind

*

CAPTCHA Image
Play CAPTCHA Audio
Reload Image