MandrakeUser.Org - Your Mandrake-Linux Knowledge Base!


 
 

* DocIndex - Connectivity

Mail The Unix Way - Postfix

* Postfix and Sendmail
* Configuring Postfix
* Checking The Hostname
* Configuring Your Mail Program
Scenario 1: Delivering mail via an external mail server
Scenario 2: Delivering mail by yourself
Scenario 3: Pretend to have a full-blown SMTP server
* Testing Your Setup

Related Resources:

Postfix Documentation, Howtos and FAQs

Revision / Modified: July 06, 2001 / Mar. 25, 2002
Author: Tom Berger

 

* Postfix and Sendmail

The Sendmail mail server is - with an estimated 100 million users each day - without a doubt the most widely used mail server on the Internet. So why use Postfix? Here is a quote that may shed some light upon this:
"The Sendmail configuration file is one of those files that looks like someone beat their head on the keyboard. After working with it... I can see why!" (Harry Skelton)

Postfix aims to be "fast, easy to administer, and secure, while at the same time being Sendmail compatible enough to not upset existing users". And it's quite good at this.
If you want Sendmail anyway, you can still install it from your Mandrake Linux CD with urpmi sendmail, you should uninstall Postfix first, of course. You can save yourself a lot of trouble by using the install-sendmail script (this will also configure fetchmail for you). If you need a complex Sendmail setup, use 'webmin'.

* section index * top

* Configuring Postfix

The configuration file is '/etc/postfix/main.cf', the configuration process is explained in /usr/share/doc/postfix-[...]/html/basic.html'. Postfix is excellently documented. Changes in the configuration must be followed by this command:

service postfix reload

issued by 'root'.

Checking Hostname

In order to work properly, Postfix has to run on a machine with a fully qualified domain name (FQDN), i.e. a name in the form of 'xxxxxx.yyyy.zzz', a simple name will not do. Run the

hostname

command in order to find out if your machine fulfills this requirement.

If your machine does not have a FQDN, you have to assign one to it, e.g. by using 'draknet' from the Mandrake Control Center, or by hand editing '/etc/hosts' (only for static IPs) and '/etc/sysconfig/network'.

Configuring Your Mail Program

Configure your mail program to use your mail server. This is usually done in a configuration dialog called 'SMTP' or 'Send'. Most programs provide the opportunity to switch to 'Sendmail', which is perfectly OK, since Postfix is compatible to it. If you have to specify the path to the server's executable, use '/usr/sbin/sendmail'. Do not configure any options that might be available, you will do this in 'main.cf'. You might want to set your mail-address (the string that appears in 'From:'), though. This is easier to do in the client than at the server.

Scenario 1: Delivering mail via an external mail server

This method has the advantage that it leaves the actual delivering of the mail to a server which is connected permanently to the Internet. This server has a better chance to deliver mail to servers which are hard to reach or are temporarily disconnected.
The disadvantage is that you usually have to use the mail-address given to you by your provider. Most providers do not allow relaying mail using a self-made sender-address.

Add this line to 'main.cf':

relayhost = [mail.provider.com]

[mail.provider.com] is the name or IP address of your provider's SMTP server.

Edit '/etc/postfix/aliases' and change the second field of the last line (" Person who should get root's mail") to your user account. Now build 'aliases.db' with

postalias /etc/postfix/aliases

If you use Dial-On-Demand, you want to prevent Postfix from delivering mail if you do not explicitly tell it to do so. Add this line to 'main.cf':

defer_transports = smtp

If your machine is part of a local network which doesn't provide DNS, you should turn off DNS lookups:

disable_dns_lookups = yes

To get the mail out every time you connect to the Internet, create the file 'ip-up.local' in '/etc/ppp' and put these lines in it:

#!/bin/bash
/usr/sbin/sendmail -q

Save and run chmod +x /etc/ppp/ip-up.local to make the file executable.

If your machine gets its IP via DHCP, you might encounter some trouble with bouncing mails from your relay host (553, 'domain doesn't exist'). In this case you have to tell Postfix to strip the machine name from outgoing mails by removing the hash (#) in front of this line in 'main.cf':

myorigin = $mydomain

Restart Postfix after changing 'main.cf' and try again.

Scenario 2: Delivering mail by yourself

This method allows you to use a self-made 'from:' address in any case. You should be connected to the Internet quite often to allow Postfix delivering deferred mail (i.e. mail which couldn't be delivered at the first try). Your mail agent should include a 'reply-to' address for an external POP-account, unless you use a more sophisticated setup as described in scenario 3.

You don't have to edit 'main.cf', unless having to comply to certain circumstances mentioned in Scenario 1. Just edit 'aliases' and build 'aliases.db'.

Scenario 3: Pretend to have a full-blown SMTP server

This is a nice method to impress your friends ;-). It requires some effort, though:

  1. Register your domain name via a free domain parking service.
  2. Find a web-space provider which offers SMTP. This is the hard part. I'm using Westhost: low prices, support OK, servers running on GNU/Linux, Debian I think. (No, I don't get money for mentioning them ;-)).
  3. Transfer your domain name from the domain parking service to your new web-space account. This usually just takes a mail to the parking service where you tell them the DNS addresses of your web-space provider.

The next step is to configure your machine. You'll have to change the hostname by editing '/etc/HOSTNAME', '/etc/hosts.conf' and '/etc/sysconfig/network'.
The hostname must be an FQDN, consisting of three parts: [machine name].[domain name].[toplevel domain]. Use the domain name and top-level domain you've registered. You can use any machine name you like, but you should refrain from using "www", since your web-account already uses that one.

Having made the changes, restart the network service with/etc/rc.d/init.d/network restart. If everything went fine, hostname --fqdn should show you the FQDN of your machine.

Now configure Postfix: remove the hash-sign (#) in front of these lines in 'main.cf':

  • myorigin = $mydomain This will strip the machine name fromall mail.
  • inet_interfaces = $myhostname, localhost This makes Postfix listen only on specified network interfaces.
  • mynetworks = 192.168.0.0/28, 127.0.0.0/8 You have to adapt the first IP to the one you've assigned to your machine name in /etc/hosts. '192.168.0.0/28' however is a sure bet, since it is a valid address for local networks.

Edit 'aliases' in /etc/postfix' and build 'aliases.db' withpostaliases /etc/postfix/aliases. Add further parameters if necessary (described in Scenario 1) and restart Postfix by using the 'reload' command.

Ready! :-).

If you are using this method with a variable IP, there's one huge drawback: sooner or later you will find that more and more sites begin to reject your mail. Welcome to the DUL, the Dial-up User List! This list is used by many servers to block mail from mail servers with non-static IPs. Some people obviously have way too much time on their hands (yes, they blacklisted me too :-(().

* section index * top

* Testing Your Setup

Now it's time for a test. Your email address is [your user name]@[your machine's FQDN], but for sending mail locally, you just have to provide [username]@localhost.
On a virtual terminal, type mail -s test [your username]@localhost. On the next line, hit CTRL and 'd'. Hit ENTER on the Cc: prompt. mail will complain about the missing body, but that's OK.
Now type mail and you should see the 'test' message in your mailbox. Bingo! ;-)
If you do not see it there, quit mail with q and runmailq. This will show queued mail along with status reports (e.g. error messages).

* section index * top

* Configuring Fetchmail

 
Legal: All texts on this site are covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB (Tom Berger) and Mandrakesoft 1999-2002.