[ Current Issue Home | Issue #2 Home | FAQ ]��

The FreeBSD 'zine
Featured Articles: Email
## Email with a Dynamic IP Dial-up Account
## Oben O. Candemir <>

Setting up mail on a FreeBSD box can be one of the most challenging parts of configuring a stand-alone workstation. If you are like the majority of home users and use an ISP for your internet access then there are a few tricks that you need to set mail up successfully. The FreeBSD handbook has an excellent section on setting up 'user PPP' using the tun0 pseudo device; and therefore readers who haven't set that up already are referred to that source.

The official Sendmail site has an extensive FAQ dealing with setup of sendmail that can be daunting to a new user. This article will attempt to describe one setup of mail using tools that I will assume are installed on the stand-alone machine and are described below:

1) Sendmail: I would strongly urge use of version 8.9.2 that compiles on FreeBSD 2.2.8 without any drama whatsoever. It has several improvements in dealing with mail relaying (preventing people from using your machine as a mail gateway for spam). How sendmail 8.9.2 can be compiled and installed is described very well by Dan Langille on his site. Sendmail can be configured using the 'm4' program and Dan gives an example '.mc' file that m4 will use to generate the essential '/etc/sendmail.cf' file.

Stand-alone machines using the default sendmail.cf file will send incorrect `From' headers and this can sometimes cause problems with both sending mail (bounced when the user's domain can't be verified) or in receiving replies from people who you've mailed to. This problem can be overcome by using a feature of sendmail called 'masquerading'. When enabled this feature tacks on your ISP's (or whatever you set in fact) domain to your local user name; allowing proper delivery and receiving of mail. The sendmail 8.9.2 distribution includes a default setup for BSD 4.4 type systems that will generate a sendmail.cf that is similar to what you probably already have. If you would like to use masquerading and smart relaying of mail to your ISP (so it does all the hard work of translating the email address into a computer to deliver to) I would suggest using the following '.mc' file that I name 'FreeBSD.mc':

  # FreeBSD.mc sendmail m4 configuration file for masquerading and smart
  # mail relaying.

  VERSIONID(`fireball.2000.com.au bsd4.4.mc - Version 1.0 - 17/01/1999')
  define(SMART_HOST, `your.isp.mail.host')
  define(`confDOMAIN_NAME', `your.own.domain.here')dnl


Note the 'your.own.domain.here' that appears three times needs replacing with your domain name (try typing 'hostname' at a command prompt if you are not sure what to use). The other two things that need changing are 'isp.domain.here' and 'your.isp.mail.host'. The first needs to be changed to whatever appears after the '@' in the email address your ISP gave you. For example the email address '[email protected]' requires the use of 'bogus.com.au' in the lines above. The 'your.isp.mail.host' needs to be replaced with the name of the outgoing SMTP mail server your ISP would have given you.

Now I'd give the commands to generate the sendmail.cf file but it is essential that you go over some of the stuff in the README file located in the '_path_to_sendmail_source/cf' directory for how to generate a sendmail.cf file from the configuration .mc file given above using the m4 program. (It is a line starting 'm4 ....')

Become the superuser (su) and install the generated sendmail.cf file into the /etc directory after backing up your previous sendmail.cf file (you'll be glad you did if you have made any errors). If sendmail is running (examine the output from 'ps ax |grep sendmail'), kill it in the usual manner.

Type 'sendmail -v -bi'. This will give you some output and should cause sendmail to read the new configuration file and rebuild the aliases database. The important thing is that there are no error messages. The two possible errors are firstly, you may get a complaint that the sendmail.cf file is not of the correct version. Sendmail 8.9.2 has reduced default support for much of the `older' style things like uucp. The second problem can be that file permissions for the mail related files in /etc are 'loose'. Go over the main README file in the sendmail 8.9.2 for the solution to problems with permissions on those files.

That's the sendmail configuration out of the way.

2) The second step is to become the superuser again and create a new user on your system that is named whatever appears in the first part of your email address. Taking the example from above '[email protected]' would require a user with a login name of 'obenc'. If your local login name is the same as your ISP user login name then you can skip this step altogether (you are already set up). The reason we do this is so that sendmail will tack on the ISP domain onto the proper user name. There are other ways of doing this but setting up a new user that has only mail duties is a useful way of administering a system. Therefore type 'adduser <ispusername>' and go through the process of answering the questions. (An important point is to use no password for this user if you want to start the mail program in step 5 without requiring a password or if you intend to start it from a window manager's menus. Note that using no passwords is a security risk and the telnet service should be turned off for a start. Otherwise use a password. The only thing in this users directory is going to be mail and all the mail files will have permissions of 0600.

Now onto Fetchmail and its configuration...

3) Fetchmail 4.6.7: This program replaces the older 'popclient' software. It is a relatively simple program that has some nifty features for stand-alone users that access their mail from their ISP's mail server. Fetchmail can deal with IMAP servers but my ISP (and I suspect many others) uses POP3 so I will describe only POP3 setup.

We will be setting fetchmail up to run as a 'daemon' process whenever we connect to our ISP using the 'PPP' program. I normally start PPP interactively from a root account (it can be set up to allow users access but my setup uses a nifty little trick that requires root to be the user dialing up the ISP).

The first step in setting up fetchmail is to make a '.fetchmailrc' file in the directory of the mail user you just created. The following will suffice:

  # Sample .fetchmailrc file

  set daemon 300
  poll <your.isp.mail.host>
  protocol pop3
  localdomains <your.own.domain.here>
  user <isp_mail_username> with password <isp_mail_password>
  to * here

  poll <another.alternate.mail.host>
  protocol pop3
  localdomains <your.own.domain.here>
  user <another_username> with password <another_password>
  to * here

The fields to complete in <..> are straightforward (do not type the '<' or '>' :) and the values should be the same as we used above. The 'set daemon 300' line sets fetchmail up to run as a daemon checking mail every 300 seconds (5 minutes); you can change this to your taste. The file also shows that you can have more than one POP3 server listed. See the fetchmail man pages for other options.

The only other thing that is advisable is to 'chmod 600 .fetchmailrc' to protect the file from viewing by others (it contains your passwords after all).

The final part of the fetchmail puzzle is how to get it running. This can be done in two ways. Manually (not advised); you have to 'su <mail_username>' and type 'fetchmail'. Or better, modify your '/etc/ppp/ppp.linkup' (you'll have to be root to do this) file to start fetchmail whenever you connect to your ISP. You will already have set up PPP before (see Handbook for excellent instructions). Here is an example of what you need to include in the /etc/ppp/ppp.linkup file to start fetchmail automatically when you connect to your ISP:

  # /etc/ppp/ppp.linkup

    delete ALL
    add default HISADDR

    !bg sendmail -q
    !bg su <mail_username> -c fetchmail

  #  ... other stuff


Note that you have to replace the <mail_username> (again without the '<' and '>') with the local mail user we created earlier (if you had to create it). This simply runs the fetchmail as that mail user and therefore the .fetchmailrc in the mail user home directory will be used.

Another thing to note is the sendmail line. I start my sendmail at boot time (you can do that by changing the /etc/rc.conf file); if you don't start sendmail at boot time then you will need to change the line to read:

	!bg sendmail -bd -q15m

That is a fairly standard way to start sendmail as a background daemon and to tell it to check its queue (located in /var/spool/mqueue) every 15 minutes. Feel free to alter the frequency. Note: only root should start sendmail as a daemon; so the line above will work only if you have followed my recommendation to start PPP as root, but will fail if you use a user account to start PPP.

The fetchmail program will automatically check for new email every 5 minutes with the setup above. If you don't receive mail very frequently then you can lengthen this to a more suitable interval. You can 're-awaken' the daemon before the scheduled times by typing the 'fetchmail' command on an xterm or terminal that you have logged in or su'd to the mail user account. If you type 'fetchmail' on your normal login account (assuming it is not the same as your mail user account) and you have no .fetchmailrc file then you will get some complaints from fetchmail. Or if you do have a .fetchmailrc then mail will end up in your login account's mailbox (ie. usually not what's intended).

I also use Procmail to sort my mail into folders according to their relevance and importance to me. Setting up Procmail is relatively straightforward but completely optional therefore I won't go into its setup (others have already done a good job at it anyhow... it may be the subject of another article).

Setting up the Mail Program...

4) Install Pine v4.05 if you haven't already. Pine is just so much better in all respects than other terminal based programs like 'elm' or 'mail' that you should do yourself a favour and install it. You can use the other programs but count yourself as a masochist.

5) The final step is to arrange an easy way to access your mail from your normal login account. This only applies to people who had to create a new local mail user account to match their ISP username as in step 2 above. You can do this easily by creating a script named something like 'startmail'. If you use X and would like pine to appear in its own window make 'startmail' contain the following:

  # A script to change the user to the mailuser and fire up pine

  su <mail_username> -c 'xterm -geometry 120x40 -T "Mail" -e pine'


for terminal only users, use the following 'startmail' script:

  # A script to change the user to the mailuser and fire up pine

  su <mail_username> -c pine


Replace <mail...> in each case as above with your user name from step 2. Remember to 'chmod 755 startmail'. You may also want to modify the '-geometry 120x40' to something suiting your screen size.

When you run startmail you will be asked for the mail users password. If you set up without a password then pine should come up without needing a password.

Note that if you did not use a password, the instruction above can be included in the configuration files of the various window managers and started conveniently whenever you need to use your email account. So it can be started for example from a Dock application if you use Windowmaker or from a menu if you use Blackbox (my favorite two window managers).

I hope that this short discussion has helped you in setting up mail delivery on your machine. Please feel free to send me any feedback or corrections on the material here. Address email to -> Oben O. Candemir <>. Questions are best directed to the various mailing lists that deal with the programs above.

Congratulations. You should now have an excellent mail setup that will serve you well for many years without problems :)

  Copyright (c) 1999 by Oben O. Candemir <[email protected]>
  This may be used for fair non-commercial purposes without the consent
  of the author provided this copyright notice accompanies any usage of
  the material herein. The instructions here are provided AS IS; no
  responsibility whatsoever is taken for any damage caused by following
  them properly or otherwise.

Return to Issue #2

Contact: <>
Last modified: $Date: 1999/06/26 05:24:30 $
Copyright � 2023, The FreeBSD 'zine
All rights reserved.