Tuesday, April 10, 2012

Step by Step Mail Server Configuration (on trail)
===================================
Step 1. Check the postfix Installation
     => dpkg -s postfix

Step 2. Check the status of Postfix
=> lsof | grep postfix
=> pgrep postfix
=> service postfix status
=> netstat -ntlp | grep master    
=> netstat -ntlp | grep 25    

Step 3. Change the MTA (if sendmail is already installed)
=> update-alternatives --config mta

Step 4. Remove previous Installation

Step 5. Install Postfix MTA (Mail Transfer Agent)
=> aptitude install postfix postfix­tls libsasl2 sasl2­bin libsasl2­modules popa3d
During installation, postfix will ask for few questions like name of server and answer those questions by entering your domain name and select Internet site for postfix.

Step 6: Configure Postfix MTA (Mail Transfer Agent)
Step 6.a: Creating a Fully Qualified Domain Name
=> postconf ­e myhostname=mail.example.com (host name following domain)
(Setting myhostname is important because a Fully Qualified Domain Name will also change the setting for  mydomain. If FQDN is mail.example.com then the parameter form mydomain is automatically example.com.)

Step 6.b: Edit main.cf file
=> gedit /etc/postfix/main.cf
myhostname = mail.example.com
mydomain = example.com
inet_interfaces = all

Step 6.c: Configure Relays
=> gedit /etc/postfix/main.cf
mydestination = $mydomain
If would like to also accept mail for hostname may also add this information to the configuration
mydestination = $mydomain, $myhostname
If CNAMEs have created in DNS settings for the domain that would also need to be added here
mydestination =
    $mydomain,
    $myhostname,
    www.$mydomain,
    tech.$mydomain
Each line ends with a comma and starts with a space

Step 6.d: Configure outgoing domain
The outgoing domain parameter provides a way to verify where mail came from. This parameter setting will be used by Postfix whenever mail is sent for an address that is not fully qualified
=> gedit /etc/postfix/main.cf
myorigin = $mydomain

Step 6.e: Change Network Settings
=> gedit /etc/postfix/main.cf
mydomain = example.com
myorigin = $mydomain
myhostname = mail.example.com
mydestination = $myhostname, localhost, localhost.$mydomain
mynetworks = 192.168.3.0/24
inet_interfaces = all

Step 6.f: Restart Postfix
=> /etc/init.d/postfix restart
=> service postfix restart

Step 7: root Mail Configuration
create an alias for the root user so that mail that is intended for root will be delivered to a non­privileged user
=>gedit /etc/aliases (and create a line like following)
root: mukul
Whatever user you choose make sure that it is an account that is on the system. Do not use the admin account as it is tied to other things on the system.
Once you have added the username run the command:
=> newaliases

Step 8: Testing the Current Configuration
   First verify that postfix is running
   => /etc/init.d/postfix stop
   => /etc/init.d/postfix start
   => /etc/init.d/postfix reload

Step 8: Send a test message to root

Step 9: Check the mail
=> echo test | /usr/sbin/sendmail ­f root root
=> tail /var/log/mail.log

If you do this command you should see your mail:
   less /var/mail/mukul

Step 10: Test with Telnet
=> telnet localhost 25
or
=> telnet mail.example.com 25
HELO mukul.example.com
250 mail.example.com
MAIL FROM: < root@example.com
This e­mail address is being protected from spambots. You need JavaScript
enabled to view it >
250 Ok
RCPT TO: <mukul@localhost>
250 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
This is a test mail from telnet.
.
250 Ok: queued as 276E1794BF1
QUIT
221 Bye
Connection closed by foreign host.

Step 10.a: Now Check the mail for user mukul (or any user)
=> less /var/mail/mukul

Step 11: Install Dovecot
Dovecot is POP3/IMAP server which needs MTA like Postfix to work properly.
=> aptitude install dovecot­imapd dovecot­pop3d dovecot­common

Step 11.a: Edit the dovecot configuration file
=> gedit /etc/dovecot/dovecot.conf
# specify protocols = imap imaps pop3 pop3s
protocols = pop3 imap
# uncomment this and change to no.
disable_plaintext_auth = no
pop3_uidl_format = %08Xu%08Xv

Step 11.b: Create a user to test our pop3 mail with outlook
=> adduser user_name
(Always create a separate user to test your mail or ftp.)

Step 11.c: Restart Dovecot
=> /etc/init.d/dovecot restart
To test with outlook express only enter username with password

Step 12: Configure SASL Authentication with TLS
SASL Configuration + TLS (Simple authentication security layer with transport layer security) used mainly to authenticate users before sending email to external server, thus restricting relay access.

Without SASL authentication configuration it will be NOT possible to send mail outside of the local network. If it is tries to send email outside of network "relay access denies" error will be shown from outlok express. However, there will be no problems in receiving email from outlook
Edit as the following:
=> gedit /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = yourdomain.com
smtpd_recipient_restrictions =
permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous

postfix does a chroot so it can’t communicate with saslauthd.
#rm ­r /var/run/saslauthd/
#mkdir ­p /var/spool/postfix/var/run/saslauthd
#ln ­s /var/spool/postfix/var/run/saslauthd /var/run
#chgrp sasl /var/spool/postfix/var/run/saslauthd
#adduser postfix sasl

Step 13: Configure Dovecot authentication
On the Dovecot side you also need to specify the dovecot authentication daemon socket. In this case we specify an absolute pathname.
=> gedit /etc/dovecot/dovecot.conf

Look for the line that starts with auth default, before that insert the lines below.
   auth default {
   mechanisms = plain login
   passdb pam {
   }
   userdb passwd {
   }
   socket listen {
   client {
   path = /var/spool/postfix/private/auth
   mode = 0660
   user = postfix
   group = postfix
   }
   }
   }
Now, rename previous auth default to auth default2. If you dont rename this then dovecot server will give you error like multiple instances of auth default.

Step 14: Restart all the following components of Mail Server
=> /etc/init.d/saslauthd restart
=> /etc/init.d/postfix restart
=> /etc/init.d/dovecot restart

Test whether your mail server works or not with your outlook express. Configure a user with a user name (without @domain) and make sure that you select my server requires authentication. Under settings select same as incoming mail server

Note:
1. If you dont enable My server requires authentication in outlook you cannot send emails to external recipients and you get relay access denied error.
2. Do not use root login to login to your mail server.
3. Dont forget to create a new user before you authenticate using outlook.

Step 15: Forwarding Mails
Ever wondered how to forward your mails especially if you are a webmaster managing number of sites. You might need to forward any email sent to your primary email address. Its that easy. Just create a .forward file on your home directory. Insert list of emails addresses separated by commas, where you want to get forwarded.
Login as user and type
=> echo ‘destination_email_address’ > .forward
or you can use vi to create .forward file. Just Delete .forward file if you dont want any forwarding.

Step 16: Installing Squirrel Web Mail
Before installing Squirrel Web Mail you need to make sure you have installed apache2 with php support
=> aptitude install apache2
=> aptitude install libapache2­mod­php5 php5­cli php5­common php5­cgi
=> aptitude install squirrelmail
Squirrelmail configuration file is located in: /etc/squirrelmail/ folder. By default all settings are preloaded.
Run squirrelmail configuration utility as ROOT
=> /usr/sbin/squirrelmail­configure

Step 17: Setup to run under Apache
Edit apache configuration file /etc/apache2/apache2.conf
=> gedit /etc/apache2/apache2.conf
   Include /etc/squirrelmail/apache.conf

Step 17.a: Restart Webserver
=> /etc/init.d/apache2 restart

Step 17.b: Access webmail
   http://yourdomain or server ip/squirrelmail
Create a separate local user and login as a new user.

Step 18: Mail Server Logs
Always refer to logs located in /var/log/mail.log so that you can identify what the problem is before you can troubleshoot.
=> cat /var/log/mail.log
=> cat /var/log/mail.log | less
=> cat /var/log/mail.log | grep mukul

------------- (taken help from net) ---------
------------arahman.iit@gmail.com -------

1 comment:

  1. This is sheriff i want to know how to create thunderbird to my users i am using linux server in that server i am having two ethernet card eth0 for direct internet connection to server eth1 for users. i am assume my users default gateway address eth1:192.168.0.206 this gateway only my user using this gateway address only. so please tell me how to create thunderbird to my users?

    ReplyDelete