Make Sendmail accept mail from external sources - gHacks Tech News

Make Sendmail accept mail from external sources

When you're setting up servers the last thing you want to have to do is put in an all nighter in order to get Sendmail accepting email from outside of your local network. If you're new to Linux this can be a real nightmare. The good news is once this is configured, it'll just keep on working until you take it down. But getting Sendmail to the point where it is working correctly can be a real nightmare.

In this article I will give you a step by step setup for getting Sendmail to accept email from outside of localhost and your own LAN. This will require you to manually edit some configuration files and you will need root access (or sudo access) in order to do this.

In order for this to work I am going to assume you have your own domain name. For the sake of this article we'll illustrate with the sample domain www.sampledomain.com. I will also assume this FQDN is working properly and you have Sendmail already installed and starts properly. The operating system I am using for this example is Ubuntu Server 8.10. With that in mind, let's get to this.

/etc/mail

All of the configurations you will be doing will be within the /etc/mail directory. In this directory you will be modifying the following:

  • sendmail.cf
  • sendmail.mc
  • access
  • local-host-names

Once all of the modifications are made you will then restart Sendmail.

sendmail.mc

By default Sendmail is setup to only accept mail from localhost. This is the first change that needs to be made. This change is made in the sendmail.mc file. What you are looking for is the following line:

DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Addr=127.0.0.1, Port=smtp')dnl

The line needs to be altered to look like:

DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp')dnl

The Addr=127.0.0.1 section instructs Sendmail to only accept email from localhost.

Now you need to add these changes to the sendmail.cf file by issuing the command:

sudo make -C /etc/mail

This will add your changes. The reason I use sendmail.mc for these options is that configuring the DAEMON_OPTIONS is a bit confusing and hard to find. The other options are quite easy to add directly to sendmail.cf.

sendmail.cf

The options you will want to add in this file are for setting your domain name.  The first option is under the "my official domain name" heading. What you will see in the example is:

#Dj$w.Foo.Com

replace this with (and remember we're using our sample domain):

Djsampledomain.com

The next option will be set for masquerading. In some recent Sendmail releases this is not in the cf by default. Take a look for the quoting section that looks like:

# dequoting map
Kdequote dequote
# class E: names that should be exposed as from this host, even if we masquerade
# class L: names that should be delivered locally, even if we have a relay
# class M: domains that should be converted to $M
# class N: domains that should not be converted to $M
#CL root

At the bottom of this add:

# who I masquerade as (null for no masquerading) (see also $=M)
DMsampledomain.com

Now you are done with the sendmail.cf file.

access

This file defines access control to your mail server. For our sample we will add the following to the bottom of this file:

sampledomain.com
www.sampledomain.com
mail.sampledomain.com

Save that file and you have one more configuration to take care of.

local-host-names

This file will define the host names associated with your Sendmail server. In this file we will add:

sampledomain.com
mail.sampledomain.com

Restart Sendmail

It is now time to restart Sendmail. Do this with the command:

/etc/init.d/sendmail reload

Once sendmail restarts you should be accepting email from the outside world. Run a test with an email address outside of your domain.

Final thoughts

Sendmail isn't really as difficult as it is made out to be. With this simple walkthrough you should have Sendmail accepting mail from all over quickly and easily.

Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. Anony mouse said on December 11, 2009 at 12:31 am
    Reply

    Very helpful! Was able to get emails from outside my organization using Red Hat 5. For Red Hat 5 users, make sure to install the sendmail-cf package, or else your ‘make -C /etc/mail’ will fail.

  2. Ramon said on May 2, 2013 at 3:18 pm
    Reply

    Amazing, worked very well!

  3. Van Tate Jr said on February 14, 2014 at 7:02 pm
    Reply

    Great and simple write-up.

  4. ron said on April 17, 2014 at 8:07 am
    Reply

    No need to setup mx, a, cname, text files on the DNS for the server?

  5. Karl Rapson said on December 13, 2016 at 8:31 pm
    Reply

    Where do I put myname for myname@sample.com please advise thanks – k

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.