Mail The Unix Way - Postfix
Summary:
- 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
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 why1.1 " (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
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:
#1.1 /bin/bash<br> /usr/sbin/sendmail -q
Save and run
chmod +x /etc/ppp/ip-up.local
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:
- Register your domain name via a free domain parking service.
- 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 ;-)).
- 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 hostname must be an FQDN, consisting of three parts:
{machine name}.{domain name}.{toplevel domain}
Having made the changes, restart the network service with
/etc/rc.d/init.d/network restart
hostname ––fqdn
Now configure Postfix: remove the hash-sign (#) in front of these lines in 'main.cf':
-
myorigin = $mydomain
-
inet_interfaces = $myhostname, localhost
-
mynetworks = 192.168.0.0/28, 127.0.0.0/8
postaliases /etc/postfix/aliases
Ready1.1 :-).
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 List1.1 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 :-(().
Testing Your Setup
Now it's time for a test. Your email address is
{your user name}@{your machine's FQDN}
{username}@localhost
On a virtual terminal, type
mail -s test {your username}@localhost
Now type
If you do not see it there, quit
q
mailq
Next Item: Configuring Fetchmail
Related Resources:
Postfix Documentation, Howtos and FAQs
Revision / Modified: July 06, 2001 / Mar. 25, 2002
Author: Tom Berger
Legal: This page is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft.
Document data
- Lost account?
- Join the community, be part of the Club: it's free!
- Get the PWP Download Subscription!