Friday, 4 October 2013

Scripts Used for Mail Migration from Qmail to Sendmail

Please follow My blog for Sendmail Installation and then follow these scripts to migrate Qmail Users on Sendmail. Here i used Mailbox format Maildir in migration.


The Mail User Credentials file for Qmail domain users resides into /home/vpopmail/domains/<domain name>/vpasswd file. Here I will migrate test user of Qmail to Sendmail server.

Example:
[root@qmail ~]# cat /home/vpopmail/domains/example.com/vpasswd

test:$1$r8OZxMDG$uqwnzkwkLaUQR2hWHeldK.:1:1:TEST:/home/vpopmail/domains/example.com/0/test:NOQUOTA:ComplexPassword

Description:-

Username: test
Encrypted Password: $1$r8OZxMDG$uqwnzkwkLaUQR2hWHeldK
Description: TEST
Home directory: :/home/vpopmail/domains/example.com/0/test
Quota: NOQUOTA
Clear Password: ComplexPassword


1.       I saved all Qmail accounts into userlist file on Sendmail server and create a script to create all users on sendmail server.

[root@mail01 scripts]# vi user_create

#/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for i in `cat userlist`
 do
   echo $i > 4
   cat 4

   mailid=$(awk -F":" '{print $1}' 4)
   username=$(awk -F":" '{print $5}' 4)
   password=$(awk -F":" '{print $4}' 8)

 # User Creation on Mail Server

useradd -c "$username" -m -d /home/$mailid -s /sbin/nologin $mailid ; echo $password | passwd --stdin $mailid

done
IFS=$SAVEIFS


2.       Run rsync command on Qmail Server to sync all data from Qmail Server to Sendmail Server.

# rsync –avz  /home/vpopmail/domains/<DomainName>/      <Sendmail IP>:/home/


3.       Change permission on Sendmail Server.

[root@mail01 scripts]#  chown  root.root  /home
[root@mail01 scripts]#  chmod 755 /home

4.       To change Permission of Users home directory on Sendmail server,  Create a list of users into accounts file.

On Qmail:

[root@qmail ~]# cat /home/vpopmail/domains/example.com/vpasswd | cut –d: -f1 > acccounts
[root@qmail ~]#scp accounts  <sendmail IP>:/scripts/accounts

On Sendmail:

[root@mail01 scripts]# vi /scripts/accounts
test
jitendrakumar
.
.
.

5.       Create Script to change Permission of users on their home directories.

[root@mail01 scripts]# vi perm_change

#!/bin/bash

for i in `cat accounts`
do
 id $i
 if [ $? == 0 ]
   then
      chown -R $i.$i /home/$i
   else
     echo " User *****$i***** doesn't exist"
     echo $i >> /scripts/noid
fi

done

Virtualusertable Configuration on Sendmail Server

Incoming E-mail messages can be sorted based on the recipient domain name with thevirtusertable utility. Because user accounts are not directly associated with any specific domain names, a virtusertable must be used to differentiate between recipient domain names. For example, a virtusertable mapping will allow you to direct E-mail messages forwebmaster@mydomain.name and webmaster@subhost.name to different users on your VPS v2.

Configuring Virtusertable mappings

In order to create virtusertable mappings, you must first create a text file in the /etc/mail/directory of your server (there is a sample file in that directory named virtusertable.sample). This file will contain virtusertable mappings.
Each entry in a virtusertable should be on a single line. The original recipient address on the left hand side, with one or more spaces or tabs separating it from the right hand side, which contains the destination address. Using the example above, the virtusertable mapping would be as follows:
webmaster@mydomain.name     tom
webmaster@subhost.name      steve  
The original recipient is the E-mail address that people will send messages to, and can be either a full address (username@domain.name), or a catch all for all messages to the specified domain (@domain.name). If you want to create multiple virtusertable entries for a single domain, make sure that you put the catch all below any other entries for that same domain name. For example:
webmaster@mydomain.name    tom
support@mydomain.name      someuser@hotmail.com
john@mydomain.name         john
@mydomain.name             john
The destination address should be a local user, an alias, or a remote E-mail address. You may also use a %1 to indicate that the original user should be prepended to a catch all.
Any time you make a change to the /etc/mail/virtusertable text file, you will need to create a db file that sendmail can read. The following command will create the/etc/mail/virtusertable.db file when run by root:
# makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
Alternatively, a shorter version of this same command can be used:
# vnewvirtmaps

Example Virtusertable Entries

The following entry would deliver any message sent to floyd@example.com to the local account floydr.
floyd@example.com                                      floydr
The next entry will deliver a message sent to john@example.com to his personal E-mail account with his ISP.
john@example.com                                       jfranklin@my-isp.com
Any other E-mail sent to the super-host.com domain will go to Floyd's local account.
@super-host.com                                           floydr
Anything sent to a user at example.net will be sent to example.com, but will not change the username the message was originally sent to (only the domain is modified).
@example.net                                                  %1@example.com
The following entry will reject mail addressed to any address at the example.net domain that isnot defined in the virtusertable file. The sender will receive an appropriate error code plus the description, "User unknown."

@example.net                                                  error:nouser User unknown

Using "Mailertable" force Sendmail to route mail to specific hosts or mailserver

Mailertable allows you to route or deliver mail to different hosts. You need to use feature called FEATURE(`mailertable') and you will have to create an external database containing the routing information for various domains.
First include mailertable feature you need to edit your sendmail.mc file and add the following line:
FEATURE(`mailertable'):

Open sendmail config file using text editor:
# vi /etc/mail/sendmail.mc
Append/modify line as follows:
FEATURE(`mailertable')
Regenerate sendmail configuration file using m4:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Restart Sendmail service:
# /etc/init.d/sendmail restart
Open /etc/mail/mailertable file and add domain name to route to different hosts. For example all mail coming from network 192.168 route to mail.myisp.com and all email for test.in will be automatically forwarded to a mail server mail.example.com.
# vi /etc/mail/mailertable
Append following lines:
192.168. smtp:mail.myisp.com
test.in smtp:mail.example.com
Now build database version of the mailertable is built using:

# makemap hash /etc/mail/mailertable Or just type make command to build new mailertable.db file.

MAILMAN Mailing List Installation and Configuration in SENDMAIL

Mailman is a server based email list and web based list member management software. It allows list users to send a single email to the list email address (i.e. list@example.com) and all members on the list will receive the email. It is a great communications tool for the dissemination of information and for discussion among list members. Mailman will also save list emails for archive and viewing via the web. A full featured email web GUI is also provided for list members and list administrators.

1.    I will install mailman package on server for mailing list.

[root@mail01 jitendrakumar]# yum install mailman*

[root@mail01 jitendrakumar]# rpm -qa | grep mailman
mailman-2.1.12-18.el6.x86_64

Mailman now installs to following location.

/etc/mailman/...
/usr/lib/mailman/...
/var/spool/mailman/...
/var/lock/mailman/...
/var/run/mailman/...
/var/log/mailman/...
/usr/share/doc/mailman-*

2.    Create a site admin password.

[root@mail01 jitendrakumar]#/usr/lib/mailman/bin/mmsitepass <your-supersecret-password>

3.    Change the following parameters to file /usr/lib/mailman/Mailman/mm_cfg.py (to override defaults set in /usr/lib/mailman/Mailman/Defaults.py)

DEFAULT_URL_HOST   = 'mail01.example.com'
DEFAULT_EMAIL_HOST = 'example.com'

4.    Other config files:

I)             /usr/lib/mailman/Mailman/Defaults.py - System defaults. Don't change here
II)            override in /usr/lib/mailman/Mailman/mm_cfg.py
III)          /etc/mailman/sitelist.cfg - Mailman behavior and settings.
IV)          /etc/mailman/mm_cfg.py is a soft link to /usr/lib/mailman/Mailman/mm_cfg.py

5.    Generate the default Mailing list mailman.

[root@mail01 jitendrakumar]#/usr/lib/mailman/bin/newlist mailman      
      Enter the email address of the person running the list:  admin@example.com

      Initial mailman password:    - Type it correctly. There is no verification!       

This will generate "aliases" entry to cut and paste to the file /etc/aliases

## mailman mailing list
mailman:              "|/usr/lib/mailman/mail/mailman post mailman"
mailman-admin:        "|/usr/lib/mailman/mail/mailman admin mailman"
mailman-bounces:      "|/usr/lib/mailman/mail/mailman bounces mailman"
mailman-confirm:      "|/usr/lib/mailman/mail/mailman confirm mailman"
mailman-join:         "|/usr/lib/mailman/mail/mailman join mailman"
mailman-leave:        "|/usr/lib/mailman/mail/mailman leave mailman"
mailman-owner:        "|/usr/lib/mailman/mail/mailman owner mailman"
mailman-request:      "|/usr/lib/mailman/mail/mailman request mailman"
mailman-subscribe:    "|/usr/lib/mailman/mail/mailman subscribe mailman"
mailman-unsubscribe:  "|/usr/lib/mailman/mail/mailman unsubscribe mailman"

6.    Update Aliases file.

[root@mail01 jitendrakumar]# makemap hash /etc/aliases.db < /etc/aliases

7.    Generate additional mailing list.

[root@mail01 jitendrakumar]#/usr/lib/mailman/bin/newlist  alluser-noida    

8.    For Web interface  of mailman admin console we have to make entry into /etc/httpd/conf.d/mailman.conf.

[root@mail01 jitendrakumar]# vi  /etc/httpd/conf.d/mailman.conf

ScriptAlias /mailman/ /usr/lib/mailman/cgi-bin/
<Directory /usr/lib/mailman/cgi-bin/>
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

Alias /pipermail/ /var/lib/mailman/archives/public/
<Directory /var/lib/mailman/archives/public>
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

# Uncomment the following line, replacing www.example.com with your server's
# name, to redirect queries to /mailman to the listinfo page (recommended).

# RedirectMatch ^/mailman[/]*$ http://www.example.com/mailman/listinfo

9.    Restart Apache Service on Mail Server.

[root@mail01 jitendrakumar]# service httpd restart

10.  To access the Mailling list through Web Browser use below URL.

http://Server Hostname>/mailman/admin/

Some Important Commands of Mailman:-

1.    Remove the Mailing List

/usr/lib/mailman/bin/rmlist –a <mailing list name>

 Example:

[root@mail01 bin]# /usr/lib/mailman/bin/rmlist  -a test

To finish removing your mailing list, you must edit your /etc/aliases (or
equivalent) file by removing the following lines, and possibly running the
`newaliases' program:

## test mailing list
test:              "|/usr/lib/mailman/mail/mailman post test"
test-admin:        "|/usr/lib/mailman/mail/mailman admin test"
test-bounces:      "|/usr/lib/mailman/mail/mailman bounces test"
test-confirm:      "|/usr/lib/mailman/mail/mailman confirm test"
test-join:         "|/usr/lib/mailman/mail/mailman join test"
test-leave:        "|/usr/lib/mailman/mail/mailman leave test"
test-owner:        "|/usr/lib/mailman/mail/mailman owner test"
test-request:      "|/usr/lib/mailman/mail/mailman request test"
test-subscribe:    "|/usr/lib/mailman/mail/mailman subscribe test"
test-unsubscribe:  "|/usr/lib/mailman/mail/mailman unsubscribe test"

Removing list info
Removing private archives
Removing private archives
test public archives not found as /var/lib/mailman/archives/public/test
test public archives not found as /var/lib/mailman/archives/public/test.mbox

2.    Add New Member through file containing each mail in new line.

/usr/lib/mailman/bin/add_members  -a  y  -r  <filename>   <Mailing List>

  --welcome-msg=<y|n>
    -w <y|n>
        Set whether or not to send the list members a welcome message,
        overriding whatever the list's `send_welcome_msg' setting is.

    --admin-notify=<y|n>
    -a <y|n>
        Set whether or not to send the list administrators a notification on
        the success/failure of these subscriptions, overriding whatever the
        list's `admin_notify_mchanges' setting is.

3.    Remove List of User from mailing list.

/usr/lib/mailman/bin/remove_members -f  /<filename>   <Mailing List>

4.    To generate aliases of currently listed mailing list

/usr/lib/mailman/bin/genaliases

5.    To check and fix the permissions on mailman files.

/usr/lib/mailman/bin/check_perms –f

Option -f means forcefully.

6.    Find Member into mailing list.

/usr/lib/mailman/bin/ find_member   <member mail >

Ex-

[root@mail01 bin]# ./find_member  jitendrakumar
jitendrakumar@example.com found in:
     mailman
     alluser-noida