Friday 10 August 2012

Postfix Mail Server In Debian Enterprise Linux 6.0.2.1 32 Bit Version

   

In below document line start & end with *** consider as my comments.

Add the below line in /etc/apt/sources.list
   2.      apt-get update
   3.      apt-get install mysql-server
         ***mysql pw: mypass (I given)***
   4.      apt-get install php5-mysql php5-imap postfix postfix-mysql dovecot-imapd dovecot-pop3d libsasl2-modules sasl2-bin apache2
   5.      copy postfixadmin_2.3.4.tar.gz to mail server
   6.      tar xzvf postfixadmin_2.3.4.tar.gz -C /var/www/
   7.      mv /var/www/postfixadmin-2.3.4/ /var/www/postfixadmin/
   8.      Log-in into mysql as below, create database and grant user access:
  9.  mysql -u root -h localhost –p
   10.  create database postfix_mail;
   11.  GRANT ALL PRIVILEGES ON postfix_mail.* TO 'postfix_admin'@'%' IDENTIFIED BY 'my_passwd';
   12.  GRANT SELECT ON postfix_mail.* TO 'postfix'@'%' IDENTIFIED BY 'my_passwd';
   13.   sed -i 's/change-this-to-your.domain.tld/example_domain.tld/g' /var/www/postfixadmin/config.inc.php
*** here my domain is localdomain.com*** so replaced example_domain.tld as localodmain.com***
   14.  Edit as below Vim /var/www/postfixadmin/config.inc.php
---------------------------------------------------------------------------
$CONF['configured'] = true;
$CONF['encrypt'] = 'md5crypt';

$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix_admin';
$CONF['database_password'] = 'my_passwd';
$CONF['database_name'] = 'postfix_mail';

$CONF['fetchmail'] = 'NO';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
----------------------------------------------------------------------------
   15.  13. ***Open url http://192.168.122.46/postfixadmin/setup.php and if everything is OK, database structure will be created and you’ll be asked for your setup password… enter something (for eg: I given ‘mypass’) and click ‘Generate password hash’, then copy this hash to /var/www/postfixadmin/config.inc.php.
E.g.:
   16.  $CONF['setup_password'] = '7e350bf1721579341d662bc3cea01d80:3c5d73ab1894e388e1466bd0df6c3aa2d1cc117e';
 ***Now enter superadmin account details on setup page and click ‘Add Admin’. PostfixAdmin installation is complete, you should be able to log-in with your new superadmin account. Now we need to configure postfix to read PostfixAdmin virtual tables.***

*** here Setup password: mypass***
***Admin email : mansoormail@localdomain.com***
***Password: mailmansoor***

               15. groupadd -g 3000 vmail
               16. useradd -d /home/vmail -m -u 3000 -g 3000 vmail

               17. Append this to /etc/postfix/main.cf:
virtual_uid_maps = static:3000
virtual_gid_maps = static:3000
virtual_mailbox_base = /home/vmail

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_mailbox_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
relay_domains = mysql:/etc/postfix/mysql_relay_domains.cf

smtpd_recipient_restrictions =
  permit_mynetworks,
  permit_sasl_authenticated,
  reject_non_fqdn_hostname,
  reject_non_fqdn_sender,
  reject_non_fqdn_recipient,
  reject_unauth_destination,
  reject_unauth_pipelining,
  reject_invalid_hostname

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous

#relay non-local mail through relay_host_address
#relayhost = relay_host_address
Create files with content:
#touch /etc/postfix/mysql_virtual_mailbox_domains.cf

hosts = 127.0.0.1
user = postfix
password = my_passwd
dbname = postfix_mail
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = 0 and active = 1

               #touch etc/postfix/mysql_virtual_mailbox_maps.cf


hosts = 127.0.0.1
user = postfix
password = my_passwd
dbname = postfix_mail
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1


               #touch /etc/postfix/mysql_virtual_alias_maps.cf


hosts = 127.0.0.1
user = postfix
password = my_passwd
dbname = postfix_mail
query = SELECT goto FROM alias WHERE address='%s' AND active = 1


               #touch /etc/postfix/mysql_relay_domains.cf


hosts = 127.0.0.1
user = postfix
password = my_passwd
dbname = postfix_mail
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = 1






               #touch /etc/postfix/sasl/smtpd.conf


pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
auxprop_plugin: rimap

              
               Update /etc/default/saslauthd with:


START=yes
MECHANISMS="rimap"
#imap server address
MECH_OPTIONS="localhost"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

Add postfix user to sasl group:
#adduser postfix sasl

1.0              Dovecot
#touch /etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=127.0.0.1 dbname=postfix_mail user=postfix password=my_passwd
default_pass_scheme = MD5-CRYPT
user_query = SELECT '/home/vmail/%d/%n' as home, 3000 AS uid, 3000 AS gid FROM mailbox WHERE username = '%u'
password_query = SELECT password FROM mailbox WHERE username = '%u'


               Edit /etc/dovecot/dovecot.conf


disable_plaintext_auth = no
mail_location = maildir:/home/vmail/%d/%n:INDEX=/home/vmail/%d/%n/indexes

auth default {
               userdb sql {
               args = /etc/dovecot/dovecot-mysql.conf
               }
               passdb sql {
               args = /etc/dovecot/dovecot-mysql.conf
               }
}

***comment “passdb pam” line if it’s enabled in above configuration*** (this should not activate because we are using passdb sql as per above***
Restart services:
/etc/init.d/dovecot restart
/etc/init.d/saslauthd restart
/etc/init.d/postfix restart

***Now we have functional mail server… if something don’t work, check log files /var/log/mail.log, /var/log/auth.log and /var/log/syslog***

Squirrelmail for web mail
#apt-get install squirrelmail

#squirrelmail-configure
Menu 2: server settings
Domain: localdomain.com
Sendmail or smtp : SMTP
Menu D:
Dovecot à press enter save & quit
Fetchmail
If you need fetchmail, follow this steps:
Install package:
apt-get install fetchmail
Edit /etc/default/fetchmail:
START_DAEMON=yes
Create config file:
cp /usr/share/doc/fetchmail/examples/fetchmailrc.example /etc/fetchmailrc
chmod 600 /etc/fetchmailrc
chown fetchmail /etc/fetchmailrc

Add something like below to the end of /etc/fetchmailrc file:
poll imap.gmail.com with protocol imap
user myusername@gmail.com there with password "mypasswd" is user@mydomain.tld here
keep ssl;

Restart deamon:
/etc/init.d/fetchmail restart

No comments:

Post a Comment