Install Postfix 2.6 (src install)

In Progress !!

Installing postfix

groupadd -g 4000 postfix
groupadd -g 4001 postdrop
groupadd -g 5000 vmail

useradd -g 4000 -s /bin/false -d /var/spool/postfix -c “Postfix MTA” postfix
useradd -g vmail -u 5000 vmail -d /home/vmail -m

VER=2.6.7

tar zxvf postfix-$VER.tar.gz
cd postfix-$VER
make -f Makefile.init makefiles \
‘CCARGS=-DUSE_TLS -DHAS_SSL -DHAS_MYSQL -I/usr/include/openssl -I/usr/include/mysql -DUSE_SASL_AUTH \
-DDEF_SASL_SERVER=\”dovecot\”‘ ‘AUXLIBS=-L/usr/lib -L/usr/lib/mysql -lmysqlclient -lz -lm -lssl -lcrypto’
make

sh postfix-install \
manpage_directory=/usr/man \
readme_directory=/usr/doc/postfix-$VER/README_FILES \
html_directory=/usr/doc/postfix-$VER/HTML \
config_directory=/etc/postfix \
sample_directory=/etc/postfix/sample \
daemon_directory=/usr/libexec/postfix \
command_directory=/usr/sbin/ \
queue_directory=/var/spool/postfix \
sendmail_path=/usr/sbin/sendmail \
newaliases_path=/usr/sbin/newaliases \
mailq_path=/usr/sbin/mailq \
mail_owner=postfix \
setgid_group=postdrop \
-non-interactive

cd /etc/postfix
mkdir ssl
cd ssl
openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 720
postfix set-permissions

Here are  working examples of main.cf

++++++++++
main.cf
++++++++++

inet_interfaces=all
myhostname = my-domain.ca
myorigin = $mydomain
mydestination = $mydomain, localhost
mynetworks = 127.0.0.0/8 !192.168.1.212 192.168.1.0/24
mynetworks_style = host

alias_maps = mysql:/etc/postfix/mysql-conf/mysql-aliases.cf
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-conf/mysql-virtual_forwardings.cf,
proxy:mysql:/etc/postfix/mysql-conf/mysql-aliases.cf

relay_domains =

virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-conf/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-conf/mysql_virtual_mailbox_maps.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

message_size_limit = 20480000
maximal_queue_lifetime = 5d
bounce_queue_lifetime = 5d
smtp_helo_timeout = 60s
smtpd_soft_error_limit = 3
smtpd_hard_error_limit = 12
qmgr_message_active_limit = 40000
qmgr_message_recipient_limit = 40000

smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

#=============================================
#INTERNAL FILTERS
#+++++++++++++++++++++++++++++++++++++++++++++
##body_checks = regexp:/etc/postfix/hash-files/body_checks
#=============================================
#client_conriection_rate_time_unit = 60s
#smtpd_client_connection_rate_limit = 30
#=============================================

smtpd_helo_required = yes
smtpd_recipient_limit = 120
smtpd_data_restrictions =  reject_unauth_pipelining
smtpd_recipient_restrictions =
permit_sasl_authenticated, permit_mynetworks,
check_helo_access hash:/etc/postfix/hash-files/helo_checks,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,reject_unknown_recipient_domain,
reject_unknown_sender_domain,reject_unauth_destination,
reject_invalid_hostname,
check_policy_service unix:private/python-spf
#check_helo_access hash:/etc/postfix/hash-files/helo_checks,

smtpd_sender_restrictions =
permit_mynetworks, permit_sasl_authenticated,
reject_non_fqdn_sender, reject_unknown_sender_domain
#Opportunistic TLS
#================================
smtpd_tls_security_level = may
smtp_tls_ciphers = export
smtp_tls_protocols = !SSLv2
#================================
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.pem

transport_maps = proxy:mysql:/etc/postfix/mysql-conf/mysql_virtual_transport.cf
virtual_create_maildirsize = yes
virtual_maildir_extended = yes
virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-conf/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = “The user is over quota.”
virtual_overquota_bounce = yes
proxy_read_maps = $local_recipient_maps
$mydestination $virtual_alias_maps $virtual_alias_domains
$virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps
$relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps
$relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps

#AMAVIS-NEW
#=============================================
#soft_bounce = yes
content_filter = smtp-amavis:[127.0.0.1]:10024
#=============================================

#MAILDROP
#=============================================
maildrop_destination_recipient_limit = 1
virtual_transport = maildrop
#=============================================

#DOVECOT_SIEVE
#=============================================
##dovecot_destination_recipient_limit = 1
##virtual_transport = dovecot
##mailbox_command = /usr/libexec/dovecot/deliver
##spamfilter_destination_recipient_limit = 1
#==============================================

Now we have to create POSTFIX SQL TABLES

mysql -u root -p _root_pw_

CREATE DATABASE email_db;
GRANT ALL PRIVILEGES ON email_db.* TO mail_username@’%’ identified by ‘mail_password’; FLUSH PRIVILEGES;
USE `email_db`;

CREATE TABLE `domains` (
`domain` varchar(50) NOT NULL,
PRIMARY KEY (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `users` (
`email` varchar(80) NOT NULL,
`home` varchar(255) NOT NULL default ”,
`password` varchar(255) NOT NULL default ”,
`quota` varchar(10) default ‘10485760’,
`uid` int(11) NOT NULL default ‘0’,
`gid` int(11) NOT NULL default ‘0’,
PRIMARY KEY (`email`)
) ENGINE=MyISAM;

CREATE TABLE `transport` (
`domain` varchar(128) NOT NULL default ”,
`transport` varchar(128) NOT NULL default ”,
UNIQUE KEY `domain` (`domain`)
) ENGINE=MyISAM;

CREATE TABLE `forwardings` (
`source` varchar(80) NOT NULL,
`destination` text NOT NULL,
PRIMARY KEY (`source`)
) ENGINE=MyISAM;

CREATE TABLE `aliases` (
`id` smallint(3) NOT NULL auto_increment,
`alias` varchar(50) NOT NULL default ”,
`destination` varchar(100) NOT NULL default ”,
`enabled` tinyint(1) NOT NULL default ‘1’,
PRIMARY KEY (`id`)
) ENGINE=MyISAM

INSERT INTO `domains` VALUES (‘_DOMAIN_’);
INSERT INTO `users` VALUES (‘postmaster@_DOMAIN_’, ‘/home/vmail/’, ‘_CRYPT_PASSWD_’, _QUOTA_, 5000, 5000);
INSERT INTO `forwardings` VALUES (‘postmaster@_DOMAIN_’, ‘user@_OTHER_DOMAIN_’);

…and now creating /etc/postfix/mysql-conf/mysql* files

  1. mysql-virtual_email2email.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = users
    select_field = email
    where_field = email
    hosts = 127.0.0.1
  2. mysql-virtual_forwardings.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = forwardings
    select_field = destination
    where_field = source
    hosts = 127.0.0.1
  3. mysql_relay_domains_maps.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = domains
    select_field = domain
    where_field = domain
    hosts =127.0.0.1
  4. mysql_virtual_domains_maps.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = domains
    select_field = domain
    where_field = domain
    hosts = 127.0.0.1
  5. mysql_virtual_mailbox_maps.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = users
    select_field =CONCAT(SUBSTRING_INDEX(email,’@’,-1),’/’,SUBSTRING_INDEX(email,’@’,1),’/’)
    where_field = email
    hosts = 127.0.0.1
  6. mysql_virtual_mailbox_limit_maps.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = users
    select_field = quota
    where_field = email
    hosts = 127.0.0.1
  7. mysql_virtual_transport.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = transport
    select_field = transport
    where_field = domain
    hosts = 127.0.0.1
  8. mysql-virtual_sender.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = users
    select_field = email
    where_field = email
    hosts = 127.0.0.1
  9. mysql_virtual_alias_maps.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = aliases
    select_field = destination
    where_field = alias
    hosts = 127.0.0.1
  10. mysql-aliases.cf
    user = mail_username
    password = mail_password
    dbname = email_db
    table = aliases
    select_field = destination
    where_field = alias
    hosts = 127.0.0.1
    additional_conditions = and enabled = 1

Setting up DOVECOT with SIEVE support

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s