this 2all

Centos mail server

How to install SMTP, POP3, IMAP and Webmail service 



As the name implies, this is the main configuration file for Postfix. One main attribute with Postfix is that the defaults generally default to something sensible, so that for the most part, outside of the parameters that need to be customized to your setup, they can be completely omitted in

Hint: The command below will show the configuration directives that have been altered from default.

	postconf -n

Since this is an email gateway only meant to forward email, disable local mail delivery by (Note: setting a configuration directive to empty disables it):

	mydestination =
local_recipient_maps =
local_transport = error:local mail delivery is disabled

Normally, emails that originate from a host will have a from address in the form of [email protected]. However, since the email gateway cannot receive mail for local users (as disabled above), you need to set the originating domain to something sensible:

	myorigin =

mynetworks = define which networks are allowed to relay mail through this host. Although it's meant for internal networks to be able to relay mail without having to authenticate, it can be used (abused) to include external IP addresses or networks. However, the proper solution is to set up your Postfix installation to do SASL authentication:

	mynetworks =,

This section below prevents addresses such as [email protected] to match. Explicitly define domains you wish to accept using relay_domains below.

	parent_domain_matches_subdomains =

relay_domains = define domains for which the email gateway will accept emails.

	relay_domains =,,

smtpd_recipient_restrictions = controls what the Postfix server will accept during the RCPT TO command.

	smtpd_recipient_restrictions =

transport_maps = holds the mappings between domains and the SMTP server where the mail gets forwarded. See /etc/postfix/transport for details.

	transport_maps = hash:/etc/postfix/transport

relay_recipient_maps = points to a file that lists all of the email addresses for which the email gateway will accept mail. See/etc/postfix/relay_recipients.

	relay_recipient_maps = hash:/etc/postfix/relay_recipients

show_user_unknown_table_name = controls whether Postfix returns "User unknown in relay recipient table" (default - useful for debugging only) or "User unknown" (when set to no).  This configuration directive is only used in conjunction with relay_recipient_maps.

	show_user_unknown_table_name = no

ven though local mail delivery is disabled, the email gateway is still supposed to accept emails to postmaster and abuse. To do so, define a virtual alias map (we'll populate the values later). See /etc/postfix/virtual for details.

	virtual_alias_maps = hash:/etc/postfix/virtual



This file basically defines services that Postfix will provide. To completely disable local mail delivery, edit /etc/postfix/ and insert a #symbol in front of the local service definition:

	#local     unix  -       n       n       -       -       local



In a typical setup, /etc/aliases is used  to forward mail to other account or external addresses.  However, since local mail delivery is disabled, modifying /etc/aliases has no effect. This file holds the alias mappings between local addresses and actual email addresses. Note: this is only necessary because there is no local mail delivery, and that some "local" addresses ought to exist for technical correctness. 

	postmaster      [email protected]
abuse [email protected]
root [email protected]

Actually, you can use this file for more than local addresses.  You can forward emails from ex-users to their new emails addresses, create simple distribution lists, or copy an email to another user, etc.

	[email protected]      [email protected]
[email protected] [email protected],[email protected],[email protected]
[email protected] [email protected]
[email protected] [email protected],[email protected]



This file defines the relationship between domains and the server(s) where mail is forwarded.    



This file folds a complete list of email address for which the email gateway will accept mail. Even though you have to enter the values as a pair (key & value), the second part (the value) doesn't actually matter as long as the email addresses are correct.

	[email protected] OK
[email protected] OK
[email protected] OK
[email protected] OK
[email protected] OK
[email protected] OK




Populating relay_recipients from Active Directory

Note that this script requires perl and Net::LDAP. However, this does NOT have to be on your email gateway.

	$VALID = "/etc/postfix/relay_recipients";
  • Note that if you have email distribution lists that need to be externally accesible, that you will also need the contents of:
	$hqbase="ou=Exchange Distribution Lists,dc=example,dc=com";

Hashing Databases

Postfix uses the db hash format by default. For this setup, we need to create the hashed db files by executing:

	postmap hash:/etc/postfix/virtual
postmap hash:/etc/postfix/transport
postmap hash:/etc/postfix/relay_recipients

Note: remember to rerun the above commands every time the contents of those files change.