Basic Sendmail Setup

Sending email from your server can be used for about a million different things. Working on a project recently, I realized I had never set up my server to send email to external addresses (like Gmail, for example). On a sidenote, because of the email-to-SMS services that all mobile carriers provide, this also allows you to text mobile phones (assuming you know their mobile number and carrier). Keep in mind, this tutorial is strictly for SENDING email. Receiving or processing email is not included in this tutorial.

For this post, I’ll be setting up sendmail on my CentOS virtual machine. Please see the about page for system specs. Keep in mind that this tutorial should also work for RHEL and Fedora servers.

Sendmail should be installed by default on most Linux operating systems. On CentOS/RHEL systems, the sendmail config files will be in /etc/mail

As always, it’s prudent to make backups before we start changing anything.

[alex@server mail]$ sudo cp

You’ll need to ‘sudo’ unless you are logged in as the root user since we are in /etc. OK – now if we botch anything, at least we can go back.

Now – is the configuration file of interest, but we don’t have to modify the file directly. Instead, we’ll be modifying and ‘pushing’ those changes to More on this later. For now, let’s modify I use vim for my text editing in CentOS.

[alex@server mail]$ sudo vim

Again, use ‘sudo’ – otherwise you won’t be able to commit/save your changes. There are two lines that we need to change, the SMART_HOST line and the DAEMON_OPTIONS line. The SMART_HOST line needs to have your email relay server information. Your ISP should provide a relay server, and you can generally find this information on Google pretty easily. As a Time Warner Cable customer in Milwaukee, I need to use ‘’. On the DAEMON_OPTIONS line, remove the ‘’ segment. Your config file should read like this:

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

Now, here is the “black box” part of the tutorial. In theory, you should be able to commit those changes using the following command:

[alex@server mail]$ sudo m4 /etc/mail/ > /etc/mail/

Now, that command failed for me with a “Permission Denied” error. Luckily I found another sendmail tutorial with a suggestion.  I still need to dig up the “why” behind this, hence my comment that this is the “blackbox” portion of the tutorial. I had to use ‘ksh’ as a workaround, thusly:

[alex@server mail]$ sudo ksh -c 'm4 /etc/mail/ > /etc/mail/'

Now, whenever you change a config file for a service, regardless of OS, you should restart the service. This is just a best practice in general, even if you don’t NEED to restart, it won’t hurt anything either (obviously don’t do this if you’re in a high availability environment or at work or something…). I’ve seen a lot of time wasted troubleshooting because someone forgot to restart a service. In this case, you may have to switch to root to restart the sendmail service.

[alex@server mail]$ su -
[root@server ~]# /etc/init.d/sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@server ~]#

That’s it – if you want to send an email, just type “mail”. You’ll be prompted for a subject line – enter text, then hit Ctrl+D. You’ll be prompted for a CC: address – either enter text or leave it blank, and hit Ctrl+D again. Your email is sent!


Update/Edit: I got help and information from a lot of sites, so I thought I would provide them here.
The ksh workaround for committing changes to
List of Time Warner Cable email relay servers:
Basic sendmail usage:
Sendmail and cron:

  1. November 7, 2012 at 00:16

    I always spent my half an hour to read this webpage’s content daily along with a cup of coffee.

    • November 10, 2012 at 08:27

      Thanks ddos, glad to hear you’re enjoying the site!

  1. No trackbacks yet.

Care to share your two cents?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: