Postfix

  • Postfix is a Sendmail-compatible MTA that is designed to be secure, fast, and easy to configure.
  • To improve security, Postfix uses a modular design, where small processes with limited privileges are launched by a master daemon. The smaller, less privileged processes perform very specific tasks related to the various stages of mail delivery and run in a change rooted environment to limit the effects of attacks.
  • Configuring Postfix to accept network connections from hosts other than the local computer takes only a few minor changes in its configuration file. Yet for those with more complex needs, Postfix provides a variety of configuration options, as well as third party add-ons that make it a very versatile and full-featured MTA.

The Postfix executable is /usr/sbin/postfix. This daemon launches all related processes needed to handle mail delivery.
Postfix stores its configuration files in the /etc/postfix/ directory. The following is a list of the more commonly used files:

    access — Used for access control, this file specifies which hosts are allowed to connect to Postfix.
    main.cf — The global Postfix configuration file. The majority of configuration options are specified in this file.
    master.cf — Specifies how Postfix interacts with various processes to accomplish mail delivery.
    transport — Maps email addresses to relay hosts. 

The aliases file can be found in the /etc/ directory. This file is shared between Postfix and Sendmail. It is a configurable list required by the mail protocol that describes user ID aliases.

main.cf

SETTING MY HOSTNAME
When mail cleints and server meet, they greet each other with their DNS hostnames. If the the host name is same as the name you want postfix to use to greet mail clients, there is nothing to change. On the other hand, if the hostname is set as host.example.com and you want to make the greeting to the clients as mail.example.com, change the myhostname line main.cf

  myhostname = xyz.example.com

As soon as hostname is set, postfix can automatically derive mydomain. Instead of setting myhostname, you can set only mydomain

  mydomain = example.com

myorigin: This parameter specifies the domain that should be used to qualify e-mail addresses that have no domain part at all.

   myorigin = $mydomain     ## or
   myorigin = $myhostname

mydestination: It tells Postfix which domains are considered local, that is, which domains should be delivered to UNIX accounts on this machine. Unlike mydomain and myorigin, mydestination may contain multiple domains separated by space or commas. By listing example.com here, Postfix will accept messages addressed to joe@example.com and deliver them to the UNIX user "joe". One important property of local domains is that they are all considered equal. If example.com and example.net are both listed in mydestination, joe@example.com will be equivalent to joe@example.net.

   mydestination = $mydomain, example.net, $myhostname, localhost.$mydomain

mynetworks and mynetworks_style: It control which hosts are allowed to use your server as a relay. Setting these incorrectly may allow your server to be abused by spammers and the likes, so it is important that you get them right. By default, all hosts on the subnets that your server is directly connected to will be allowed access

  mynetworks = 192.168.1.0/24
  mynetworks_style = class   # To allow the whole subneet class
  mynetworks_style = subnet  # To allow the whole subnet
  mynetworks_style = host    # To allow only a particular host

relayhost: To deliver all outbound messages indirectly via another relay server.

  relayhost = example.com
  relayhost = [mail.example.com]
  relayhost = [1.2.3.4]

inet_interfaces: This parameter decides the network interfaces that Postfix will use for both listening to new connections and sending out messages.

   inet_interfaces = all

For relaying

To Enable relay for domains
Form shell

 echo "relay_domains = /etc/postfix/relay" >> /etc/postfix/main.cf
 echo "[DOMAIN NAME HERE]" >> /etc/postfix/relay
 echo "[DOMAIN NAME HERE] smtp:[IP ADDRESS TO FORWARD TO] >> /etc/postfix/transport
 postmap /etc/postfix/transport
 postfix reload

to add additional domains:

 echo "[DOMAIN NAME HERE]" >> /etc/postfix/relay
 echo "[DOMAIN NAME HERE] smtp:[IP ADDRESS TO FORWARD TO] >> /etc/postfix/transport
 postmap /etc/postfix/transport
 postfix reload

Supporting programs

  • mailq: Views the current contents of the Postfix queue. The output includes the size, time of arrival, sender address, and recipient address/addresses of each message. Internally mailq just invokes the postqueue command and exists only for backwards compatibility with the sendmail mail transfer agent.
  • newaliases: Uses the postalias command to rebuild all local alias files. Local aliases will be covered in the Virtual alias domains and local aliases section.
  • postalias: Rebuilds a single alias file or queries an alias lookup table.
  • postcat: Shows the contents of a binary queue file residing in the Postfix queue.
  • postconf: Shows the current or default values of Postfix's configuration parameters. Can also modify the main configuration file, which can be useful in scripts.
  • postfix: Starts, stops, or restarts Postfix, or reloads its configuration. Can also be used to check the integrity of the queue directories and a few other seldom-used administrative tasks.
  • postmap: Rebuilds an indexed database file used for table lookups or queries any lookup table. The Troubleshooting lookup tables with postmap section discusses how this can be used to debug a Postfix setup.
  • postsuper: Allows you to take actions on already queued messages, for example deleting or re-queuing them. It can also perform a structural check on the queue directories and fix problems such as queue files having the wrong names. Such a check is, for example, necessary if the whole queue directory has been moved or restored from a backup.
  • postqueue: Apart from carrying out the work for the mailq program, postqueue can also be used to flush the queue. Flushing a queue means moving all messages in the deferred queue to the active queue. This can be useful to schedule immediate message delivery, but be careful. If your server is heavily loaded and performing badly, flushing the queue will only make matters worse. The sendmail program can also be used to flush the queue, again for compatibility reasons.

Changing the default mta on a red hat system:

Aternatives creates, removes, maintains and displays information about the symbolic links comprising the alternatives system.

 # alternatives --config mta
 There are 2 programs which provide 'mta'.

   Selection    Command
  -----------------------------------------------
  + 1           /usr/sbin/sendmail.postfix
 *  2           /usr/sbin/sendmail.sendmail

 Enter to keep the current selection[+], or type selection number: 1

Another way to do this to install system-switch-mail

 # yum install system-switch-mail 

Run system-switch-mail and select the appropriate mail program

http://www.howtoforge.com/amavisd_postfix_debian_ubuntu
http://www.freespamfilter.org/FC4.html#_Toc110999175
http://flurdy.com/docs/postfix/

http://wiki.linuxquestions.org/wiki/Using_MailScanner/Postfix/SpamAssassin/ClamAV_in_Gentoo_Linux#What_is_Postfix.3F
http://wiki.linuxquestions.org/wiki/Using_MailScanner/Postfix/SpamAssassin/ClamAV_in_Gentoo_Linux#What_is_Postfix.3F
http://www.howtoforge.com/virtual_users_postfix_courier_mailscanner_clamav_centos
http://wiki.linuxquestions.org/wiki/Using_MailScanner/Postfix/SpamAssassin/ClamAV_in_Gentoo_Linux#What_is_Postfix.3F