Email is Good

So you want to run your very own webserver, huh? Or maybe your wondering, "Why would I want to run my very own webserver?" Well, I'll tell you a few reasons why I decided to run my own mail server. The first, of course, was to prove that I could. Second, I wanted to have mail coming from my domain. Guess I could have just spoofed a domain email address and done some forwarding, but then I would have felt like such a poser. Besides, that's what I had been doing before; I needed a new project. Lastly, I saw this killer app. It's called Squirrelmail, and I'm gonna talk about it, too. It's kind of like your own personal hotmail, without all of the spam and mailbox limits.

Man, so far, out of everything I've learned with Linux, Sendmail has got to be the hardest. I got some help on the internet, like I always do, but there was a whole lot less help than usual when It came to mail servers. Why? Who knows. It's one of two things, as I see it. Number one, Most of the people who know Sendmail had to read that gigantic O'Reilly book with the bat on the cover. If you've had to go through that, why are you gonna let the new guys off easy. OK, OK, that was just my attempt at dry humor. I think the reality is, there are a whole lot less people using Sendmail than people using, oh let's just say Mozilla Thunderbird. The more people that use a program, the more likely you are to get some help.

Well, it turns out that setting up your own email server isn't that hard after all. Just like anything, the more options you want to use, the more complex it's gonna get. I'm gonna go with what I think is a pretty nifty basic setup. If you need more, well you'll already have a really good base to start from. If you need less, just take what you need

I am making the assumption that you followed my guide and have an account through dyndns.org or someone. Either that, or you have a static IP address on the internet. Otherwise, how's all that mail gonna find you?

We're gonna start off by checking some things out. Let's just start out with this:

chmod +x /etc/rc.d/rc.sendmail

If Sendmail wasn't starting at boot time before, it will be now. If it was already starting at boot time, don't worry, you didn't break anything

Next we're gonna fire up the old text editor. Open up the file /etc/inetd.conf. We are gonna be looking for something that looks like this:


# POP and IMAP mail servers
#
# Post Office Protocol version 3 (POP3) server:
pop3    stream  tcp     nowait  root    /usr/sbin/tcpd  /usr/sbin/popa3d
# Internet Message Access Protocol (IMAP) server:
imap2   stream  tcp     nowait  root    /usr/sbin/tcpd  imapd

If your file still has these lines commented out, time to uncomment them. Now, we could restart inetd without doing a reboot, but since we've got a lot of stuff to do, we are gonna go the simple route and reboot. When your computer finishes rebooting, You are gonna run the command:

nmap localhost

You should now see at least the following


Starting nmap 3.50 ( http://www.insecure.org/nmap/ ) at 2004-05-15 17:08 PDT
Interesting ports on localhost (127.0.0.1):
(The 1645 ports scanned but not shown below are in state: closed)
PORT    STATE SERVICE
25/tcp  open  smtp
110/tcp open  pop3
143/tcp open  imap

You probably have a lot more open ports than that, but this isn't the security section, so we're not gonna worry about it. At this point, you may have a fully functioning mail server. We are going to configure it, now. This is where most people get lost, because it's not just a matter of editing one file. Not to worry, we're gonna take it step by step.

We are gonna start by backing up a file that we are gonna be using to configure Sendmail. This way, if we eff it up, we can always go back to the beginning. Type:

cp /usr/share/sendmail/cf/cf/sendmail-slackware.mc /usr/share/sendmail/cf/cf/sendmail-slackware.mc.orig

Now, we're gonna open up /usr/share/sendmail/cf/cf/sendmail-slackware.mc in our most favorite text editor. We are gonna look for the line that looks like this:

dnl# These settings help protect against people verifying email addresses
dnl# at your site in order to send you email that you probably don't want:
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl

And we're gonna change it to look like this:


dnl# These settings help protect against people verifying email addresses
dnl# at your site in order to send you email that you probably don't want:
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun,goaway')dnl

This increases your mail server security a bit.

Next, we're gonna change our smart relaying feature. You see, a lot of big mail servers aren't going to accept your email. They think your a spammer. Your no spammer, right? To get your mail through, we are going to first send it through your ISP's mail server, then your ISP's mail server will send it out to where ever it needs to go. To do this, you need to know the name of your ISP's mail server. It is probably something like smtp.myisp.com. We'll just assume that this is the name of your ISP's mail server for this article and you can adjust accordingly. Anyway, look for the line that looks like this:


dnl# Uncomment the line below to send outgoing mail through an external server:
dnl define(`SMART_HOST',`mailserver.example.com')

And change it to look like this:


dnl# Uncomment the line below to send outgoing mail through an external server:
define(`SMART_HOST',`smtp.myisp.com')

You can adjust more settings if you know what you are doing, but that's gonna do it for me. Save the file and we're off to the next step. Follow along. This will create a new /etc/mail/sendmail.cf file (Sendmail's configuratioin file) based on the changes that you made to the sendmail-slackware.mc file.


cd /usr/share/sendmail/cf/cf
cp sendmail-slackware.mc config.mc
m4 /usr/share/sendmail/cf/m4/cf.m4 config.mc > /etc/mail/sendmail.cf

Now, we should be on easy street. I'm gonna restart Sendmail with the new configuration file. But first, I want to watch what happens to make sure that there aren't any errors. Open up a console and type

tail -f /var/log/maillog

It doesn't matter what it says at this point. We just want to watch it to make sure there are no errors reported during the next step. Open up another console and restart Sendmail with the command:

/etc/rc.d/rc.sendmail restart

Hopefully, you didn't see any new error messages in either of your consoles. You are rockin' now. You'll probably want to start testing out you new mail server. I like to use pine to check everything out. If you don't know how to use pine, just type:

pine

The directions are amazingly simple to follow. Send out some emails. Make sure to send some to local users and other people. Preferably, send the messages to other email accounts of your own that you may have. I send out messages to like four different email accounts of my own, one of which is a normal user on my box. Next, go check all of your other inboxes. Did you get the message at all of them? Good. Now, reply from all of your other boxes and make sure you receive the replay message. If you got no errors, your work here is done.

Now here's something cool you can do. Do you get email at work? Well you can check your home email from work now. Just tell your boss that I said it ways OK. Set up a new account on your works email client (Outlook, Outlook Express, whatever). For the incoming mail server name, type in the name of your computer, for instance user.dyndns.org. For the type, pick POP3 (or IMAP, but if you don't know what you're doing, POP3 is easier) . For your user name, choose a user name from your home computer and type in the appropriate password. For the outgoing mail server, you're gonna have to stick with the outgoing mailserver you currently use at work. Your computer won't allow "relaying" of messages at this point. That's a good thing, as spammers can't use your mail server

Well, we're all done. I'm gonna post how to install squirrelmail, a cool web based email program, in the future. First I have to get your webserver up and running. So move right along to the next section for now. There's more great stuff coming later.

Valid HTML 4.01! Valid CSS!