Listing 5.17 : Configure the Postfix

advertisement
ACKNOWLEDGEMENTS
This project is very important for us.Because we learned lots of benefits.This project is
very precious because we didn’t know anything about Postfixadmin and Linux but search about
them.We did our project from zero and we feel can do everything if we want.
We would like thank to our instructor Assist.Prof.Dr. Devrim Seral.First we didn’t know
anything about Linux(Ubuntu) operating system and Postfix (MTA) ,but Mr. Devrim Seral stand
behind us and he show us a way. We are eternally indebted to him. We couldn’t decide to what
will we do and how will we do, he give us examples and site names. He is a milestone for us.And
we thank you to our family and friends,because they help us very much, if they don’t we can’t be
successful. We are very happy for our graduation in CIU. It is a small university but we had very
valuable teachers in this school. They give us projects to improve ourselves, they show us ways
everytime.
i
ABSTRACT
With globalizing world conditions, technology has become more important with each
passing day. Peoples who aware the importance of technology, those who keep up with
technology, they have benefit from the blessings of technology. One of the applications that keep
up with technology is a ‘mail transfer’ system. Postfix that has become an indispensable element
of technology, it becomes an important element of technology with the track of changing time
conditions. We have done a study on ‘mail transfer’ system in general. Our overall project goal
is, system as discussed in depth, to understand the functioning of the system and developed a
system.
ii
ÖZET
Küreselleşen dünya koşulları ile birlikte teknoloji her geçen gün daha da önem
kazanmaktadır. Bu önemin farkına varıp teknolojiye ayak uyduranlar teknolojinin nimetlerinden
bire bir yararlanmaktadır.
Teknolojiye bire bir ayak uyduran uygulamalardan biride “mail transfer sistem’dir.
Teknolojinin vazgeçilmez öğelerinden biri haline geline “postfix”, değişen zaman koşullarını
takibiyle birlikte teknolojinin önemli öğesi haline gelmiştir .Biz genel olarak bu sistem üzerine
bir çalışma yaptık. Projedeki genel amacımız ise sistemi derinlemesine ele alarak, sistemin
işleyişini anlamak ve sistemi geliştirmekti.
iii
Contents
Page
ACKNOWLEDGEMENTS………………………………………………………………………..i
ABSTRACT……………………………………………………………………………………….ii
ÖZET……………………………………………………………………………………………...iii
CHAPTER I ..................................................................................................................................... 1
INTRODUCTION ............................................................................................................................ 1
1.1 Project Description ................................................................................................................. 1
1.2 Goal of Project ........................................................................................................................ 2
1.3 Project Features ...................................................................................................................... 2
CHAPTER II .................................................................................................................................... 3
POSTFIX.......................................................................................................................................... 3
2.1 Structure of Postfix ................................................................................................................. 3
2.2 Installation Postfix .................................................................................................................. 4
2.3 Postfix start and stop ............................................................................................................ 10
CHAPTER III................................................................................................................................. 12
PROJECT EQUIPMENTS............................................................................................................. 12
3.1 Project Tools and Technologies ........................................................................................... 12
3.1.1 LAMP Server ................................................................................................................. 12
3.1.2 MySQL Workbench ....................................................................................................... 17
3.1.3 MySQL Administrator ................................................................................................... 18
3.1.4 Mozilla Thunderbird ...................................................................................................... 19
3.1.5 Postfix ............................................................................................................................ 19
3.1.6 Dovecot .......................................................................................................................... 20
3.2 Protocols ............................................................................................................................... 21
3.2.1 Simple Mail Transfer Protocol ....................................................................................... 21
3.2.2 Post Office Protocol(POP 3) .......................................................................................... 24
3.2.3 Comparison with IMAP ................................................................................................. 25
3.2.4 Internet Message Access Protocol(IMAP) ..................................................................... 26
CHAPTER IV ................................................................................................................................ 27
DATABASE DESIGN ................................................................................................................... 27
iv
4.1 ER Diagram .......................................................................................................................... 27
4.2 Tables ................................................................................................................................... 28
4.2.1 Create the Table Admin ................................................................................................. 28
4.2.2 Create the Domain Admin Table ................................................................................... 28
4.2.3 Create the Domain Table ............................................................................................... 29
4.2.4 Create the Alias Table .................................................................................................... 29
4.2.5 Create the Mailbox Table ............................................................................................... 30
4.2.6 Create the Log Table ...................................................................................................... 30
4.2.7 Create the Vacation Table .............................................................................................. 31
CHAPTER V .................................................................................................................................. 32
SYSTEM OVERVIEW .................................................................................................................. 32
5.1 Apt-get package management system .................................................................................. 32
5.2 Configuration of bind server................................................................................................. 33
5.3 Configuration of web server ................................................................................................. 33
5.4 Php 5 Web Programming Language ..................................................................................... 34
5.5 The configuration of mysql database ................................................................................... 34
5.6 The Configuration of Mail Server ........................................................................................ 35
5.7 SASL Installation ................................................................................................................. 36
5.8 Dovecot ................................................................................................................................. 37
5.9 Installing MySQL map support for Postfix .......................................................................... 38
5.10 Installing Packages for Client Access and Authentication ................................................. 38
5.11 Installing package for SMTP authentication ...................................................................... 38
5.12 How Postfix Virtual Domains Work? ................................................................................ 39
5.13 How Postfix Mappings Work? ........................................................................................... 40
5.14 Setting Postfix MySQL Maps ............................................................................................ 42
5.14.1 Creating Virtual Alias Maps ........................................................................................ 42
5.14.2 Virtual Domain Maps................................................................................................... 43
5.14.3 Virtual Mailbox Maps .................................................................................................. 43
5.14.4 Virtual Mailbox Quota Maps ....................................................................................... 44
5.14.5 Relay Domain Maps .................................................................................................... 44
5.15 Configuring Postfix with MySQL maps ............................................................................. 45
v
5.16 Setting up Postfix ............................................................................................................... 46
5.17 Enhanced Mail Services ..................................................................................................... 47
5.18 SMTP Authentication ........................................................................................................ 47
PROJECT PROCESS..................................................................................................................... 49
6.1 Sending a basic mail on localhost......................................................................................... 49
CONCLUSION .............................................................................................................................. 52
REFERENCES ............................................................................................................................... 53
vi
Table of Figure
Page
Figure 2.1: Mail Transfer System on Postfix ............................................................................... 3
Figure 2.3 : Mail Transfer Systems ............................................................................................ 11
Figure 3.1: PhpmyAdmin Database............................................................................................ 17
Figure 3.2 : Mysql Administrator Login .................................................................................... 18
Figure 3.3: Mozilla Thunderbird ................................................................................................ 19
Figure 3.4 : Localhost Sending Mail .......................................................................................... 24
Figure 3.5 : Pop3 Services .......................................................................................................... 25
Figure 4.1 : ER Diagram ............................................................................................................ 27
Figure 6.1 : Sending mail on localhost ....................................................................................... 49
Figure 6.2 : Lists ALL the files and directories in the /var/mail directory ................................. 50
Figure 6.3 : Looking mail on MUTT.......................................................................................... 51
Figure 6.4 : Read mail on MUTT ............................................................................................... 51
vii
Table of Listing
Page
Listing 2.1 : Add and Group User ................................................................................................ 4
Listing 2.2 : Download Postfix Packet ......................................................................................... 4
Listing 2.3 : Remove sendmail ..................................................................................................... 5
Listing 2.4 : Create New aliases ................................................................................................... 6
Listing 2.5 : Main.cf file for Postfix.............................................................................................. 6
Listing 2.6 : Postfix Main.cf ......................................................................................................... 7
Listing 2.7 : /etc/postfix/main.cf Virtual Domain Information ................................................... 7
Listing 2.8 : /etc/postfix/main.cf User aliases ............................................................................. 7
Listing 2.9 : /etc/postfix/main.cf User Accounts .......................................................................... 8
Listing 2.10 : /etc/postfix/main.cf SASL Support ........................................................................ 8
Listing 2.11 : Myhostname and Mydomain.................................................................................. 8
Listing 2.12 : Mynetworks and Virtual_mailbox_base ................................................................ 9
Listing 2.13 : Create vmail and domains below of vmail home index ......................................... 9
Listing 2.14 : Vmail and domains index writes and readrights .................................................... 9
Listing 2.15 : Postfix start .......................................................................................................... 10
Listing 2.16 : Postfix stop ........................................................................................................... 10
Listing 3.1 : Overall Flow for message creation ........................................................................ 21
Listing 4.1 : Create Database and Connect to Mysql ................................................................. 27
Listing 4.2: Admin Table ........................................................................................................... 28
Listing 4.3 : Domain_Admins Table .......................................................................................... 29
Listing 4.4 : Domain Table ......................................................................................................... 29
Listing 4.5 : Alias Table ............................................................................................................. 30
Listing 4.6 : Mailbox Table ........................................................................................................ 30
Listing 4.7 : Log Table ............................................................................................................... 31
Listing 4.8 : Vacation Table ....................................................................................................... 31
Listing 4.9 : Disconnect from the Mysql database ..................................................................... 31
viii
Listing 5.1 : Installation of Packages.......................................................................................... 32
Listing 5.2 : Remove the Packages ............................................................................................. 32
Listing 5.3 : Update of package .................................................................................................. 32
Listing 5.4 : Update the whole established package ................................................................... 33
Listing 5.5 : Update the whole system ....................................................................................... 33
Listing 5.6 : Installation and Configuration of web server ......................................................... 33
Listing 5.7 : Installation of library for apache ............................................................................ 33
Listing 5.8 : Installation of Php5 ................................................................................................ 34
Listing 5.9 : To Download Php5-cgi .......................................................................................... 34
Listing 5.10 : Download package php for mysql ....................................................................... 34
Listing 5.11 : Restart the server of Apache ................................................................................ 34
Listing 5.12 : Download some package to setup mysql-client ................................................... 34
Listing 5.13 : Mysql system is setup .......................................................................................... 35
Listing 5.14 : Create a root password for mysql ........................................................................ 35
Listing 5.15 : Connect to mysql root password .......................................................................... 35
Listing 5.16 : To download Postfix ............................................................................................ 36
Listing 5.17 : Configure the Postfix ........................................................................................... 36
Listing 5.18 : Postfix Restart ...................................................................................................... 36
Listing 5.19 : Setup SASL .......................................................................................................... 36
Listing 5.20 : Download Dovecot as POP and IMAP ................................................................ 37
Listing 5.21 : Restart Dovecot .................................................................................................... 37
Listing 5.22 : Connect to Postfix ................................................................................................ 37
Listing 5.23 : /etc/Postfix/virtual_mailboxes ............................................................................. 40
Listing 5.24 : /etc/postfix/mysql_virtual_mailbox_maps.cf ....................................................... 41
Listing 5.25 : Postfix using entry in mysql_virtual_mailboxes_maps.cf ................................... 41
Listing 5.26 : /etc/postfix/mysql_virtual_alias_maps.cf ............................................................ 42
Listing 5.27 : /etc/postfix/mysql_virtual_alias_maps.cf ............................................................ 42
Listing 5.28 : /etc/postfix/mysql_virtual_domains_maps.cf ...................................................... 43
Listing 5.29 : /etc/postfix/mysql_virtual_domains_maps.cf ...................................................... 43
Listing 5.30 : /etc/postfix/mysql_virtual_mailbox_maps.cf ....................................................... 43
Listing 5.31 : /etc/postfix/mysql_virtual_mailbox_maps.cf ....................................................... 43
ix
Listing 5.32 : /etc/postfix/mysql_virtual_mailbox_limit_maps.cf ............................................. 44
Listing 5.33 : /etc/postfix/mysql_virtual_mailbox_limit_maps.cf ............................................. 44
Listing 5.34 : /etc/postfix/mysql_relay_domains_maps.cf ......................................................... 44
Listing 5.35 : /etc/postfix/mysql_relay_domains_maps.cf ......................................................... 44
Listing 5.36 : Virtual Mailbox Domain Settings/etc/postfix/main.cf ......................................... 45
Listing 5.37 : Additional for quota support/etc/postfix/main.cf ................................................. 46
Listing 5.38 : Setting up Postfix ................................................................................................. 46
Listing 5.39 : The host name where your MX for virtual domains ............................................ 46
Listing 5.40 : Main.cf file ........................................................................................................... 46
Listing 5.41 : Setup permissions for postfix to use sasl ............................................................. 47
Listing 5.42 : Installation of package and postfixadmin ............................................................ 47
Listing 5.43 : Setup databases for postfixadmin ........................................................................ 47
Listing 5.44 : Restart apache2 .................................................................................................... 47
Listing 5.45 : SMTP Authenication ............................................................................................ 47
Listing 5.46 : In /etc/postfix/sasl/smtpd.conf file for databases ................................................. 48
x
xi
CHAPTER I
INTRODUCTION
1.1 Project Description
We have done an about three mounth work on postfixadmin configuration tool.We have
referred following topics in our three months work.

Simple mail transfer protocol (SMTP)

Post office protocol (POP)

Internet mail access protocol (IMAP)
Firstly, we have done a work about how these three protocol work ?
What type structure they have ? and how these structure configure? We have done a work
about one or two weeks on these three protocol.
After protocol work, we have done a work on about MTA (Mail Transfer Agent) and
MUA’s (Mail User Agent) structure,these two structures roles in mail transfer system and how
they would configureted ? We have benefited from many different structures in our system.Those
structures are ; Mysql, Mysql Workbench, Postfix, Dovecot, Apache, Php etc ...
Our main aim on this project ;
How mail transfer system would configureted in Linux area ?
In substance,we have had an idea in this project about: How a packet would loaded in
Ubuntu area ? How this packet would configurated ?
We have had an idea about imaginary users mail receiving and sending.
1
1.2 Goal of Project
The aim of project, we see how mail transfer system was working and how configuration
were doing in Linux field.Those configuration are necessary for mail transfer system.We have
created virtual domain through postfixadmin interface.Then we have opened virtual users over
those domain.We have provided mail transfer between those virtual users.
Eventually we have provided to users pulling mails from Mozilla Thunderbird through
using IMAP and POP3 protocol.
1.3 Project Features
More detailed information is given in the following chapters. In the following part
processes are give briefly.
These are;
 Php,Apache webserver is used.
 Mysql is used for Database Design
 Create a virtual domain and virtual users
 All of process automatically saved to database
 Virtual user can send message to each other
 Create a vmail user
 Mysql Workbench or phpMyadmin used for backup of database.

Installation of Postfix

Apt-get package management system

Create a postfix mapping and working mechanism
2
CHAPTER II
POSTFIX
2.1 Structure of Postfix
Postfix is the default Mail Transfer Agent (MTA) for Ubuntu. It is in Ubuntu's main
repository, which means that it receives security updates. This guide explains how to install and
configure postfix and set it up as an SMTP server using a secure connection below in Figure
2.1[1]
Figure 2.1: Mail Transfer System on Postfix
In our setup:

Postfix Mail Transfer Agent receives emails via the SMTP protocol and delivers them to
different places on your hard disk.

MySQL database server stores the information to control the behavior of postfix. It
knows about users, domains, email forwarding and passwords.

Courier is a standalone mail server just like Postfix but we just use its POP3/IMAP
server component to let users access the mailboxes.
3

SASL, the Cyrus library is using to authenticate your users who are dialed in at another
ISP while they are on the road they get an IP address outside of your network. Your mail
server however only trusts local IP addresses. The SASL ,Simple Authentication and
Security Layer, adds authentication to SMTP and makes your mail server trust them.
2.2 Installation Postfix
Although postfix mail server as part of a large portion of our home,yet it is very simple to
install. But what is difficult is to configure postfix to your request.Because there are unbelievable
configure parameter.We will use some parameter which is necessary for our project.Check the do
you have a another mta in your system before installing the postfix exim4 or sendmail to be
installed in your system.If possible remove them,if you don’t remove them,stop them.Let’s start
to postfix installation with user and groups installation that needs postfix.Postfix needs
“postfix’s” user and postdrop’s group during work time.User and group names are not have to be
“postfix” and “postdrop”.But postfix and postdrop users will need that user and groups while
running.Because of this situation they referred by that name[10].
Create postfix’s user and postdrop’s group through below command.”Add user”
command wants password for postfix.For that enter strongest password.
#>adduser postfix
#>groupadd posstdrop
Listing 2.1 : Add and Group User
Download postfix packet through below command to you’re in the directory.
#>wget http://www.tigertech.net/mirrors/postfix-release/official/postfix2.5.5.tar.gz
Listing 2.2 : Download Postfix Packet
4
After that through below command open packet below of usr/local/mailserver_makedir
index and go to the home directory.Order is compilation stage.Compilation postfix help of below
commands.
“Make install” command will ask to you some questions.Answer the all questions by
pressing enter.This will set up postfix to your system that default settings.But installation has not
yet finished.There are still some steps about installation.
Postfix creates a file that name is /usr/sbin/sendmail when postfix installed.Also
/usr/lib/sendmail sysmbolic link should point to the /usr/sbin/sendmail file.If there is a another
MTA in your system before installing postfix. /usr/lib/sendmail symbolic link may be pointing to
the another sendmail program.
You need to do delete /usr/lib/sendmail symbolic link and create a symbolic link with the
same name that points to the /usr/sbin/sendmail file.
For that,first delete /usr/lib/sendmail symbolic link with the help of below command.
#>rm-f /usr/lib/sendmail
Listing 2.3 : Remove sendmail
Then,creates /usr/lib/sendmail symbolic link as points to the /usr/sbin/sendmail
programme with the help of below command.
Postfix keeps mail’s nicknames inside /etc/postfix/aliases file.But doesn’t read
/etc/postfix/aliases file directory for nicknames.Instead of that reads /etc/postfix/aliases.db file.
/etc/postfix/aliases.db file has same content with /etc/postfix/aliases file.But only one different it
keeps /etc/postfix/aliases fields content as text.It keeps /etc/postfix/aliases.db content inside of
two numbers system.
/etc/postfix/aliases.db fields nicknames format.Storage bring performance to postfix.
Because reads of double fields come true very fastly then reads of text file.But,in the case of
postfix to read /etc/postfix/aliases.db the file,while we define nickname to postfix.We don’t do
describe to /etc/postfix/aliases.db file.
5
Instead of that,we describe nicknames to /etc/postfix/aliases file and we creates
/etc/postfix/aliases.db file with the help “new aliases” command.After installation finished,
/etc/postfix/aliases file creates but /etc/postfix/aliases file creates but /etc/postfix/aliases.db file
doesn’t create.Aliases.db file should create with the help of “new aliases” command.We can
create aliases.db file with the working of below command.
#>newaliases
Listing 2.4 : Create New aliases
Installation has finished now,order is adjustment of postfix.
Postfix have two adjustment file:
/etc/postfix/main.cf
Listing 2.5 : Main.cf file for Postfix
Main.cf adjustment file for postfix’s adjustment.Master.cf adjustment file for integrated of
programmes with postfix that programmes are study integrated with postfix.Postfix have a lot
integrated system as a result of postfix design.One of them Cyrus-SASL.Adjustment file
3./usr/lib/sas12/smtp.conf provides integrated study of postfix and Cyrus-SASL.
Let us first set the main file.There is no need adjustment of master.cf file for now.We will
mention adjustment of smtpd.conf file in application of Cyrus-Sasl.To get /etc/postfix/main.cf
file extra and delete all datas inside /etc/postfix/main.cf file.Paste main.cf’s content to
/etc/postfix/main.cf file which is below.
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname =hp-laptop
mydomain = hp.com
myorigin = /etc/mailname
inet_interfaces = all
unknown_local_recipient_reject_code = 550
mynetworks = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
6
home_mailbox = Maildir/
mailbox_command = /usr/bin/procmail
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/local/man
sample_directory = /etc/postfix
readme_directory = no
Listing 2.6 : Postfix Main.cf
# Virtual Domain Information
domains_server_host = localhost
domains_search_base = o=hosting,dc=myhosting,dc=example
domains_query_filter =
(&(objectClass=JammVirtualDomain)(jvd=%s)(accountActive=TRUE)
(delete=FALSE))
domains_result_attribute = jvd
domains_bind = no
domains_scope = one
Listing 2.7 : /etc/postfix/main.cf Virtual Domain Information
# User Aliases
aliases_server_host = localhost
aliases_search_base = o=hosting,dc=myhosting,dc=example
aliases_query_filter =
(&(objectClass=JammMailAlias)(mail=%s)(accountActive=TRUE))
aliases_result_attribute = maildrop
aliases_bind = no
Listing 2.8 : /etc/postfix/main.cf User aliases
7
# User Accounts
accounts_server_host = localhost
accounts_search_base = o=hosting,dc=myhosting,dc=example
accounts_result_attribute = mailbox
accounts_bind = no
accountsmap_server_host = localhost
accountsmap_search_base = o=hosting,dc=myhosting,dc=example
accountsmap_query_filter =
accountsmap_result_attribute = mail
accountsmap_bind = no
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_transport = virtual
virtual_mailbox_base = /home/vmail/domains
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_minimum_uid = 1024
virtual_uid_maps = static:1024
virtual_gid_maps = static:1001
Listing 2.9 : /etc/postfix/main.cf User Accounts
# SASL Support
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_sasl_authenticated_header = yes
broken_sasl_auth_clients = yes
smtpd_sasl_path = /etc/postfix/sasl:/usr/lib/sasl2
#smtpd_recipient_restrictions = permit_sasl_authenticated,
check_relay_domains,
reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtp_sasl_auth_enable = no
Listing 2.10 : /etc/postfix/main.cf SASL Support
When you paste above content to main.cf file,there is a point to pay attention.The lines
that started ”Path” and “ddd” must start with tabs.Please pay attention do it.There are some
parameters which changes system to system in main.cf file.The following parameters will need to
adopt your system.
#> myhostname =hp-laptop
#>mydomain = ozan.com
Listing 2.11 : Myhostname and Mydomain
8
If you enter different machine name area name in application time,set two parameters
according to that.The network may be different in your machine.Your own machine and postfix
want to see themselves as a network with parameters mynetworks place.
#> mynetworks =
localhost
#> virtual_mailbox_base = /home/vmail/domains
Listing 2.12 : Mynetworks and Virtual_mailbox_base
Virtual_mailbox_base parameter shows to user which index they can storage their
mail.Following set shows mails storage below of “/home/vmail/domains” index.But could not
creates such a index as of right now.If you notice,for that index a “vmail” user has been
created.Such a user needs.Because while mails leaving below of that index vmail’s user rights are
using for leave.We will talk about it in later stages.Now we need to do create a “vmail” user and
create “domains” below of “vmail” home index.Create “vmail” group and user through below
command.We have given group number 1001 and user number again 1001.If this numbers are
given another user and group by system, empty number with change 1001 number.
You can use a number between 1024 and 65535.You can give same number to group and user.
#>groupadd –g 1001 vmail
#>useradd –g vmail –u 1001 vmail
#>mkdir /home/vmail
#>chown –R vmail:vmail/home/vmail
Listing 2.13 : Create vmail and domains below of vmail home index
Then creates “domains” index below of vmail through following commands.”vmail” user
and group has “domain’s” index writes and readsrights. So we have done set up to virtual
#>mkdir/home/vmail/domains
#>chown –R vmail:vmail/home/vmail/domains
Listing 2.14 : Vmail and domains index writes and readrights
9
Above applications are about vmail user.Following 3 parameters are also about following
“vmail” user.
Virtual_minimum_uid parameter point to uid of vmail user.virtual_gid_maps_parameter
point to vmail group number.Above example in the number 1001.You need to do the number
below seen 101 change with the 1001.Or change with the given number of vmail user and group
numbers.Postfix application has finished.You can move to the next level.
2.3 Postfix start and stop
Let us first make the following warning.Doesn’t start postfix before the completing
Cyrus-Sasl integration with postfix.You can use following command for start postfix
#>postfix start
#> /etc/init.d/postfix start
Listing 2.15 : Postfix start
You can use following command for stop postfix.
#>postfix stop
#> /etc/init.d/postfix stop
Listing 2.16 : Postfix stop
There is command for restart postfix again.Because of,for restart postfix again,you have
to stop postfix and then you can start postfix.
10
You can achieve that with the help of above commands.
If you want to see postfix works or doesn’t work,you should “netstat-ltnp” to command
line.If you are faced with an output as follows,postfix is up and running.Each time your machine
is switched,if you want postfix’s to run automatically,add postfix’s operation command to
/etc/rc.local file.Take care to this command must come before the “exit to” line shown in Figure
2.3
Figure 2.3 : Mail Transfer Systems
11
CHAPTER III
PROJECT EQUIPMENTS
3.1 Project Tools and Technologies
These equipments are the tools required to develop the PostfixAdmin Configuration Tool system.
The tools we used to develop this system are:

LAMP which consist of
o Linux
o Mysql
o Apache
o Php5
o PhpMyAdmin

Mysql Workbench

Mysql Administrator

Postfix

Mozilla Thunderbird

Dovecot
3.1.1 LAMP Server
LAMP is an acronym for a solution stack of free, open source software, originally coined
from the first letters of Linux (operating system), Apache HTTP Server, MySQL (database
software), and PHP, principal components to build a viable general purpose web server.
The precise combination of software included in a LAMP package may vary, especially
with respect to the web scripting software, as PHP may be replaced by Perl or Python Similar
terms exist for essentially the same software suite (AMP) running on other operating systems,
such as MS Windows (WAMP), Mac OS (MAMP), Solaris (SAMP), or OpenBSD .
Though the original authors of these programs did not design them all to work specifically
with each other, the development philosophy and tool sets are shared and were developed in close
12
conjunction. The software combination has become popular because it is free of cost, opensource, and therefore easily adaptable, and because of the ubiquity of its components which are
bundled with most current Linux distributions.
The LAMP stack is widely used because it offers a great number of advantages for developers:

Easy to code: Novices can build something and get it up and running very quickly with
PHP and MySQL.

Easy to deploy: Since PHP is a standard Apache module, it’s easy to deploy a PHP app.
Once you’ve got MySQL running, simply upload your .php files.

Develop locally: It’s easy to set up LAMP on your laptop, build your app locally, then
deploy on the Web.

Cheap and ubiquitous hosting: Even the cheapest Web hosts options allow you to run
PHP and MySQL.
3.1.1.1 Linux
Linux is a Unix-like computer operating system kernel. A major emphasis of Linux
development is security, which makes it an appealing choice for a web-server application. Like
the other LAMP components, Linux is free open-source software which means the source code is
provided with operating system, which can be edited according to specific needs. Also, because
Linux-based operating systems are Unix-like, a Linux server is more natively-compatible with
other server-oriented platforms, such as Solaris and BSD, than non-Unix-like systems like
Microsoft Windows.
3.1.1.2 MySQL
MySQL is the world's most popular open source database software, with over 100 million
copies of its software downloaded or distributed throughout it's history. With its superior speed,
reliability, and ease of use, MySQL has become the preferred choice for Web, Web 2.0, SaaS,
ISV, Telecom companies and forward-thinking corporate IT Managers because it eliminates the
major problems associated with downtime, maintenance and administration for modern, online
applications.[2]
13
Many of the world's largest and fastest-growing organizations use MySQL to save time
and money powering their high-volume Web sites, critical business systems, and packaged
software including industry leaders such as Yahoo!, Alcatel-Lucent, Google, Nokia, YouTube,
Wikipedia, and Booking.com.
Main features of MySQL

Works on many different platforms.

APIs for C, C++, Java, Perl, PHP, Python, Ruby, and Tcl are available.

Fully multi-threaded using kernel threads.

Provides transactional and non-transactional storage engines.

Uses very fast B-tree disk tables (MyISAM) with index compression.

Very fast joins using an optimized one-sweep multi-join.

SQL functions are implemented using a highly optimized class library and
should be as fast as possible.

Support for aliases on tables and columns as required by SQL-92.

Handles large databases. We use MySQL Server with databases that
contain 50 million records. We also know of users that use MySQL Server
with 60,000 tables and about 5,000,000,000 rows.

Clients may connect to the MySQL server using TCP/IP sockets on any
platform.

The Connector/ODBC interface provides MySQL support for client
programs that use ODBC (Open-DataBase-Connectivity) connections.
3.1.1.3 Apache
The Apache HTTP Server is web server software notable for playing a key role in the
initial growth of the World Wide Web. In 2009 it became the first web server software to surpass
the 100 million web site milestone. Apache was the first viable alternative to the Netscape
Communications Corporation web server (currently known as Sun Java System Web Server), and
has since evolved to rival other Unix-based web servers in terms of functionality and
performance. The majority of web servers using Apache run a Unix-like operating system.
14
Apache is developed and maintained by an open community of developers under the
auspices of the Apache Software Foundation. The application is available for a wide variety of
operating systems, including Unix, GNU, FreeBSD, Linux, Solaris, Novell NetWare, Mac OS X,
Microsoft Windows, OS/2, TPF, and eComStation. Released under the Apache License, Apache
is characterized as open source software.
Apache supports a variety of features, many implemented as compiled modules which
extend the core functionality. These can range from server-side programming language support to
authentication schemes. Some common language interfaces support Perl, Python, Tcl, and PHP.
Popular
authentication
modules
include
mod_access,
mod_auth,
mod_digest,
and
mod_auth_digest, the successor to mod_digest. A sample of other features include SSL and TLS
support (mod_ssl), a proxy module (mod_proxy), a URL rewriter (also known as a rewrite
engine, implemented under mod_rewrite), custom log files (mod_log_config), and filtering
support (mod_include and mod_ext_filter).
Popular compression methods on Apache include the external extension module,
mod_gzip, implemented to help with reduction of the size (weight) of web pages served over
HTTP. ModSecurity is an open source intrusion detection and prevention engine for web
applications. Apache logs can be analyzed through a web browser using free scripts such as
AWStats/W3Perl or Visitors.[3]
3.1.1.4 Php
Hypertext Preprocessor is a widely used, general-purpose scripting language that was
originally designed for web development to produce dynamic web pages. For this purpose, PHP
code is embedded into the HTML source document and interpreted by a web server with a PHP
processor module, which generates the web page document. As a general-purpose programming
language, PHP code is processed by an interpreter application in command-line mode performing
desired operating system operations and producing program output on its standard output
channel. It may also function as a graphical application. PHP is available as a processor for most
modern web servers and as standalone interpreter on most operating systems and computing
platforms.[4]
15
3.1.1.5 PHP MyAdmin
phpMyAdmin is a free software tool written in PHP intended to handle the administration
of MySQL over the World Wide Web. phpMyAdmin supports a wide range of operations with
MySQL. The most frequently used operations are supported by the user interface (managing
databases, tables, fields, relations, indexes, users, permissions, etc), while you still have the
ability to directly execute any SQL statement shown in Figure 3.1[5]
Features:

Intuitive web interface

Support for most MySQL features:
o
browse and drop databases, tables, views, fields and indexes
o
create, copy, drop, rename and alter databases, tables, fields and indexes
o
maintenance server, databases and tables, with proposals on server configuration
o
execute, edit and bookmark any SQL-statement, even batch-queries
o
manage MySQL users and privileges
o
manage stored procedures and triggers

Import data from CSV and SQL

Export data to various formats: CSV, SQL, XML, PDF, ISO/IEC 26300 OpenDocument Text and Spreadsheet, Word, Excel.

Administering multiple servers

Creating PDF graphics of your database layout

Creating complex queries using Query-by-example (QBE)

Searching globally in a database or a subset of it

Transforming stored data into any format using a set of predefined functions, like
displaying BLOB-data as image or download-link
16
Figure 3.1: PhpmyAdmin Database
3.1.2 MySQL Workbench
MySQL Workbench enables a DBA, developer, or data architect to visually design,
generate, and manage all types of databases including Web, OLTP, and data warehouse databases.
It includes everything a data modeler needs for creating complex ER models, and also delivers key
features for performing difficult change management and documentation tasks that normally
require much time and effort. MySQL Workbench is available on Windows, Linux and Mac
OS.[6]
3.1.2.1 Visual Database Design
MySQL Workbench simplifies database design and maintenance, automates timeconsuming and error-prone tasks, and improves communication among DBA and developer teams.
It enables data architects to visualize requirements, communicate with stakeholders, and resolve
design issues before a major investment of time and resources is made. It enables model-driven
database design, which is the most efficient methodology for creating valid and well-performing
databases, while providing the flexibility to respond to evolving business requirements. Model and
Schema Validation utilities enforce best practice standards for data modeling, also enforce
MySQL-specific physical design standards so no mistakes are made when building new ER
diagrams or generating physical MySQL databases.
17
3.1.2.2 Forward and Reverse Engineering
MySQL Workbench provides capabilities for forward engineering of physical database
designs. A visual data model can easily be transformed into a physical database on a target
MySQL Server with just a few mouse clicks. All SQL code is automatically generated and runs
right the first time, which eliminates the normal error-prone process of manually writing complex
SQL code. MySQL Workbench also enables you to reverse engineer an existing database or
packaged application to get better insight into its database design. Not only can MySQL
Workbench forward and reverse engineer existing databases, but it can also import SQL scripts to
build models and export models to DDL scripts that can be run at a later time.
3.1.3 MySQL Administrator
MySQL Administrator is a program for performing administrative operations, such as
configuring, monitoring and starting and stopping a MySQL server, managing users and
connections, performing backups, and a number of other administrative tasks. Most tasks can be
performed using a command-line client such as mysqladmin, or mysql, but MySQL as shown in
Figure 3.2 [7].Administrator has the following advantages:

Its graphical user interface makes it more intuitive.

It provides a better overview of the settings that are crucial for the performance,
reliability, and security of your MySQL servers.

It displays performance indicators graphically, thus making it easier to determine and tune
server settings.
Figure 3.2 : Mysql Administrator Login
18
3.1.4 Mozilla Thunderbird
Mozilla Thunderbird is a free, open source, cross-platform e-mail and news client
developed by the Mozilla Foundation. The project strategy is modeled after Mozilla Firefox, a
project aimed at creating a web browser. On December 7, 2004, version 1.0 was released, and
received over 500,000 downloads in its first three days of release, and 1,000,000 in 10 days
shown in Figure 3.3
Figure 3.3 : Mozilla Thunderbird
3.1.5 Postfix
In computing, Postfix is a free and open-source mail transfer agent (MTA) that routes and
delivers electronic mail. It is intended as a fast, easier-to-administer, and secure alternative to the
widely-used Sendmail MTA.
It is released under the IBM Public License 1.0 which is a free software licence.
Originally written in 1997 by Wietse Venema at the IBM Thomas J. Watson Research
Center and first released in December 1998, Postfix continues as of 2010 to be actively
developed by its creator and other contributors. The software is also known by its former names
VMailer and IBM Secure Mailer.
19
Features:

Transport Layer Security

delegation of SMTP policies to an external process (this allows greylisting) and advanced
content filtering

different databases for maps: Berkeley DB, CDB, DBM, LDAP, MySQL and PostgreSQL

Mbox-style mailboxes, Maildir-style mailboxes, and virtual domains

Address rewriting (envelope and header), VERP, SMTP-AUTH via SASL

milter support compatible with Sendmail milters

using policyd-weight, Postfix can check e-mail headers against various DNSBLs and for
RFC compliance, and reject near-certain spam ahead of receiving the body of the
messages, lessening server load

compilable on AIX, BSD, HP-UX, IRIX, GNU/Linux, Mac OS X, Solaris, Tru64 UNIX
and, generally speaking, on every Unix-like operating system that ships with a C compiler
and which delivers a standard POSIX development environment. It is the default MTA on
NetBSD.
3.1.6 Dovecot
Dovecot is an open source IMAP and POP3 server for Linux/UNIX-like systems, written
primarily with security in mind. Developed by Timo Sirainen, Dovecot was first released in July
2002. Dovecot primarily aims to be a lightweight, fast and easy to set up open source mailserver.
Features:
Dovecot can work with standard mbox, Maildir, and its own experimental native highperformance dbox formats. It is fully compatible with UW IMAP and Courier IMAP servers’
implementation of them, as well as mail clients accessing the mailboxes directly.
Dovecot also includes a Mail delivery agent (called Local delivery agent in Dovecot’s
documentation), with optional Sieve filtering support.Dovecot supports a variety of
authentication schemas for IMAP and POP access including CRAM-MD5 and the more secure
DIGEST-MD5.
20
3.2 Protocols
3.2.1 Simple Mail Transfer Protocol
Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (e-mail)
transmission across Internet Protocol (IP) networks. SMTP was first defined in RFC 821 (STD
15) (1982), and last updated by RFC 5321 (2008) which includes the extended SMTP (ESMTP)
additions, and is the protocol in widespread use today. SMTP is specified for outgoing mail
transport and uses TCP port 25.
While electronic mail servers and other mail transfer agents use SMTP to send and
receive mail messages, user-level client mail applications typically only use SMTP for sending
messages to a mail server for relaying. For receiving messages, client applications usually use
either the Post Office Protocol (POP) or the Internet Message Access Protocol (IMAP) or a
proprietary system (such as Microsoft Exchange or Lotus Notes/Domino) to access their mail box
accounts on a mail server.
3.2.1.1 Mail processing model
The overall flow for message creation, mail transport and delivery may be illustrated as
follows:
sending
MUA
→
MSA
→
sending
MTA
→
receiving
MTA
→
MDA
→
Mailstore
for
retrieval by MUA
Listing 3.1 : Overall Flow for message creation
E-mail is submitted from a mail client (MUA, message user agent) to a mail server (MSA,
message submission agent) using SMTP usually. From there, the MSA delivers the mail to an
MTA, often running on the same machine. A message may be directly submitted to an MTA:
TCP port 587 is typically used for submission to MSAs (thence to MTAs), while TCP port 25
must be used for transferring to MTAs.
The MTA looks up the destination's mail exchanger record (MX record) in the Domain
name system (DNS), and relays the mail to a server on record for that domain via TCP port 25
and SMTP. (The article on MX record discusses many factors in determining which server the
21
sending MTA connects to.) Once the receiving MTA accepts the incoming message, it is
delivered via a mail delivery agent (MDA) to a server which is designated for local mail delivery.
The MDA either delivers the mail directly to storage, or forwards it over a network using either
SMTP or the Local Mail Transfer Protocol (LMTP), a derivative of ESMTP designed for this
purpose. Once delivered to the local mail server, the mail is stored for batch retrieval by
authenticated mail clients (MUAs). Mail is retrieved by end-user applications, called email
clients, using Internet Message Access Protocol (IMAP), a protocol that both facilitates access to
mail and manages stored mail, or the Post Office Protocol (POP) which typically uses the
traditional mbox mail file format or a proprietary system such as Microsoft Exchange/Outlook or
Lotus Notes/Domino. Webmail clients may use either method, but the retrieval protocol is often
not a formal standard. Some local mail servers and MUAs are capable of either push or pull mail
retrieval.
3.2.1.2 Outgoing mail SMTP server
An e-mail client requires the name or the IP address of an SMTP server as part of its
configuration. The server will deliver messages on behalf of the user. This setting allows for
various policies and network designs. End users connected to the Internet can use the services of
an e-mail provider that is not necessarily the same as their connection provider (ISP). Network
topology, or the location of a client within a network or outside of a network, is no longer a
limiting factor for e-mail submission or delivery. Modern SMTP servers typically use a client's
credentials (authentication) rather than a client's location (IP address), to determine whether it is
eligible to relay e-mail.
Server administrators choose whether clients use TCP port 25 (SMTP) or port 587
(Submission), as formalized in RFC 4409, for relaying outbound mail to a mail server. The
specifications and many servers support both. Although some servers support port 465 for legacy
secure SMTP in violation of the specifications, it is preferable to use standard ports and standard
ESMTP commands according to RFC 3207 if a secure session needs to be used between the
client and the server. Some servers are set up to reject all relaying on port 25, but valid users
authenticating on port 587 are allowed to relay mail to any valid address. A server that relays all
22
e-mail for all destinations for all clients connecting to port 25 is known as an open relay and is
now generally considered a bad practice worthy of blacklisting.
Some Internet service providers intercept port 25, so that it is not possible for their users to send
mail via a relaying SMTP server outside the ISP's network using port 25; they are restricted to
using the ISP's SMTP server. Some independent SMTP servers support an additional port other
than 25 to allow users with authenticated access to connect to them even if port 25 is blocked.
The practical purpose of this is that a mobile user connecting to different ISPs otherwise has to
change SMTP server settings on the mail client for each ISP; using a relaying SMTP server
allows the SMTP client settings to be used unchanged worldwide.
3.2.1.3 SMTP transport example
A typical example of sending a message via SMTP to two mailboxes (alice and theboss)
located in the same mail domain (example.com) is reproduced in the following session exchange.
For illustration purposes here (not part of protocol), the protocol exchanges are prefixed
for the server (S:) and the client (C:).After the message sender (SMTP client) establishes a
reliable communications channel to the message receiver (SMTP server), the session is opened
with a greeting by the server, usually containing its fully qualified domain name (FQDN), in this
case smtp.example.com. The client initiates its dialog by responding with a HELO command
identifying itself in the command's parameter with its FQDN (or an address literal if none is
available
The client notifies the receiver of the originating e-mail address of the message in a MAIL
FROM command. In this example, the email message is sent to two mailboxes on the same
SMTP server: one each for each recipient listed in the To and Cc header fields. The corresponding
SMTP command is RCPT TO. Each successful reception and execution of a command is
acknowledged by the server with a result code and response message (e.g., 250 Ok).
The transmission of the body of the mail message is initiated with a DATA command
after which it is transmitted verbatim line by line and is terminated with a characteristic sequence
23
of a new line (<CR><LF>) with just a single full stop (period) followed by another line
indication (<CR><LF>).
The QUIT command ends the session. If the second recipient were located elsewhere, the
client would QUIT and connect to the appropriate SMTP server after the first message had been
queued. The information that the client sends in the HELO and MAIL FROM commands are
added (not seen in example code) as additional header fields to the message by the receiving
server. It adds a Received and Return-Path header field, respectivelyas shown in Figure 3.4
Figure 3.4: Localhost Sending Mail
3.2.2 Post Office Protocol(POP 3)
In computing, the Post Office Protocol (POP) is an application-layer Internet standard
protocol used by local e-mail clients to retrieve e-mail from a remote server over a TCP/IP
connection. POP and IMAP (Internet Message Access Protocol) are the two most prevalent
Internet standard protocols for e-mail retrieval. Virtually all modern e-mail clients and servers
support both. The POP protocol has been developed through several versions, with version 3
(POP3) being the current standard.
24
3.2.3 Comparison with IMAP
Clients which leave mail on server generally use the UIDL command get the current
association of message-numbers to message identified by its unique identifier. The unique
identifier is arbitrary, and might be repeated if the mailbox contains identical messages. In
contrast, IMAP uses a 32-bit unique identifier (UID) that is assigned to messages in ascending
(although not necessarily consecutive) order as they are received. When retrieving new messages,
an IMAP client requests the UIDs greater than the highest UID among all previously-retrieved
messages, whereas a POP client must fetch the entire UIDL map. For large mailboxes, this can
require significant processing.
MIME serves as the standard for attachments and non-ASCII text in e-mail. Although
neither POP3 nor SMTP require MIME-formatted e-mail, essentially all Internet e-mail comes
MIME-formatted, so POP clients must also understand and use MIME. IMAP, by design,
assumes MIME-formatted e-mail shown in Figure 3.5
Figure 3.5 : Pop3 Services
25
3.2.4 Internet Message Access Protocol(IMAP)
The Internet Message Access Protocol (IMAP) is one of the two most prevalent Internet
standard protocols for e-mail retrieval, the other being the Post Office Protocol (POP).[1] Virtually
all modern e-mail clients and mail servers support both protocols as a means of transferring email messages from a server.
26
CHAPTER IV
DATABASE DESIGN
4.1 ER Diagram
Figure 4.1 : ER Diagram
The users who are wish to setup database step by step can use the following steps and
understand what table is using what purpose shown in Figure 4.1
Connect to MySQL database as root $ mysql -u root –p
Then execute the following SQL commands.
mysql>CREATE database postfix;
mysql> USE postfix;
Listing 4.1 : Create Database and Connect to Mysql
27
To create Postfix user & set password (replace postfixpassword with a password of your
choosing): mysql> GRANT SELECT ON postfix.* TO postfix@localhost IDENTIFIED BY
'postfixpassword';
To create Postfix Admin user & set password (replace postfixadmin with a password of
your choosing): mysql> GRANT SELECT, INSERT, DELETE, UPDATE ON postfix.* TO
postfixadmin@localhost IDENTIFIED BY 'postfixadmin';
4.2 Tables
4.2.1 Create the Table Admin
This table is used create the administrators for our virtual mail system. The admin user
will be able create, modify, and delete virtadomain administrators, mailboxes and other
administrative tasks in the mail system. Postfix is not using this table.
CREATE TABLE admin (
username varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY
(username),
KEY username (username)
)COMMENT=’Postfix Admin-Virtual Admins’;
Listing 4.2: Admin Table
4.2.2 Create the Domain Admin Table
Table structure for table domain_admins. This table is used to create individual
administrators for each virtual domain. Postfix or Courier is not using this table.
28
CREATE TABLE domain_admins (
username varchar(255) NOT NULL default '',
domain varchar(255) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
KEY username (username)
)COMMENT=’Postfix Admin –Domain Admins’;
Listing 4.3 : Domain_Admins Table
4.2.3 Create the Domain Table
Postfix is using the "domain" and "description" column.
CREATE TABLE domain (
domain varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
aliases int(10) NOT NULL default '0',
mailboxes int(10) NOT NULL default '0',
maxquota int(10) NOT NULL default '0',
transport varchar(255) default NULL,
backupmx tinyint(1) NOT NULL default '0',
created datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY
(domain),
KEY domain (domain)
)COMMENT=’Postfix Admin-Virtual Domains’;
Listing 4.4 : Domain Table
4.2.4 Create the Alias Table
Postfix is using the "address" and "goto" column. This table can be used for virtual
forward files.
29
CREATE TABLE alias (
address varchar(255) NOT NULL default '',
goto text NOT NULL,
domain varchar(255) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY
(address),
KEY address (address)
)COMMENT=’Postfix Admin-Virtual Aliases’;
Listing 4.5 : Alias Table
4.2.5 Create the Mailbox Table
Postfix is using the "username" and "maildir" column while Courier is using the
"username", "password", "name" and "maildir" column.
CREATE TABLE mailbox (
username varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
name varchar(255) NOT NULL default '',
maildir varchar(255) NOT NULL default '',
quota int(10) NOT NULL default '0',
domain varchar(255) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (username),
KEY username (username)
)COMMENT=’Postfix Admin-Virtual Mailboxes’;
Listing 4.6 : Mailbox Table
4.2.6 Create the Log Table
Postfix or Courier is not using this table. Instead this table is used to log the activities of
domain administrators and mailbox users.
30
CREATE TABLE log (
timestamp datetime NOT NULL default '0000-00-00 00:00:00',
username varchar(255) NOT NULL default '',
domain varchar(255) NOT NULL default '',
action varchar(255) NOT NULL default '',
data varchar(255) NOT NULL default '',
KEY timestamp (timestamp)
)COMMENT=’Postfix Admin –Log’;
Listing 4.7 : Log Table
4.2.7 Create the Vacation Table
Virtual Vacation is done with a local shell account that can receive email. The email is
then handled by a Perl script which sends the Vacation message back to the sender.
CREATE TABLE vacation (
email varchar(255) NOT NULL default '',
subject varchar(255) NOT NULL default '',
body text NOT NULL,
cache text NOT NULL,
domain varchar(255) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY
(email),
KEY email (email)
)COMMENT=’Postfix Admin – Virtual Vacation’;
Listing 4.8 : Vacation Table
Disconnect from the MySQL database:
mysql> QUIT
Listing 4.9 : Disconnect from the Mysql database
31
CHAPTER V
SYSTEM OVERVIEW
5.1 Apt-get package management system
Apt-get package management system is a package management system for development
of DEBIAN GNU/LINUX.
The meaning of it is Advanced Package Tool.When you get AP,you dont need to spend
time for steps of collection setting a package.In addition to this,w hen
the
packages
are
downloaded from official server,they are much saver than others and when a new security patch
appears.Your system will be updated immediately.Apt-get package management system appears
as predefined in the distrubition of the whole ubuntu GNU/ Linux.A package can be setup using
apt-get and you can get information and delete about package.If you want, you can set up the
packages which are connected to the program.
Installation of packages :We can set up statement at below writing to the receive only
-sudo apt-get install traceroute
Listing 5.1 : Installation of Packages
Remove the package which is set up
To remove the package which we setup,we should enter terminal
Sudo apt-get remove packet name.
Listing 5.2 : Remove the Packages
To update package archieve.To update the list of package
Sudo apt- get update
Listing 5.3 : Update of package
32
To update the whole established package
Sudo apt-get upgrade.
Listing 5.4 : Update the whole established package
To update the whole system
Sudo apt-get dist-upgrade
Listing 5.5 : Update the whole system
The management package with Aptitude
Aptitude and the management of package are nearly are the same with apt-get.
5.2 Configuration of bind server
Dns is known as Bind and its is most used by server.It is developed by ISC.The meaning
of it is Berkely Internet Naming Daemon.It undertakes the server which correspond to IP adresses
and It needs to set up to work the computer as name server.The scale files of Bind /etc/bind is
under the indexed.
5.3 Configuration of web server
Apache is the most comman HTTPD web server.Not only it supports the whole web
computing language but also brings the defination of virtualhost and the support of SSL.If we
want to give web service,we download apache with the below statement.
Sudo apt-get install apache 2
Listing 5.6 : Installation and Configuration of web server
The Apache 2 scale file exist in the /etc/apache2 indexed and apache2.conf is the basic
scale file.If we set up MySql interaction with Apache2,we should set up mysql library for apache
with the below statement.
Sudo apt-get install libapache2-mod-auth-mysql
Listing 5.7 : Installation of library for apache
33
5.4 Php 5 Web Programming Language
After we set up Apache server,we need to set up PHP.Php is the most ideal language to
develop web.Ubuntu already gives the support of php.
To download we use this statement
Sudo apt-get install php5-common php5 libapache2-mod-php5
Listing 5.8 : Installation of Php5
If we want to activate the support of CGI for Php5 we enter the below statement.
Sudo apt-get install php5-cgi
Listing 5.9 : To Download Php5-cgi
Also Php can contact connection with mysql database.We should download this package
to provide the support of php for mysql.
Sudo apt-get install php5-mysql
Listing 5.10 : Download package php for mysql
Finally we need to restart the server of Apache
Sudo /etc/init.d/apache2 restart
Listing 5.11 : Restart the server of Apache
5.5 The configuration of mysql database
Mysql is the server of Sql database with multiple user.We should download some package
to set up mysql to our server.
Sudo apt-get install mysql server mysql-client
Listing 5.12 : Download some package to setup mysql-client
34
Our mysql system is set up and works after the statement.
Sudo netstat-plutn | grep mysql
Listing 5.13 : Mysql system is setup
We can fix the server of mysql using the upper statement to make it close to access and to
reach just from the local or we can determine the IP address which will service from bind line in
/etc/mysql/my.conf file
When it is seen as bind:127.0.0.1 in the scale file it can be just reach from local.
Then the firs thing what we need to do for mysql to create a root password.
Sudo mysql admin –u root password your password
Listing 5.14 : Create a root password for mysql
Then you can reach mysql with the below statement.
Mysql –u root –p
Password:............
Postfix Admin postfixadmin@localhost
password:admin555
Listing 5.15: Connect to mysql root password
5.6 The Configuration of Mail Server
On the distrubition of Ubuntu GNU/Linux Sendmail,Qmail you can use like mta(mail
transfer agent).
Postfix is a mta which leaves behind all around sendmail and gmail.When sendmail first
appeared,it was used commonly but bugs don’t come to an end.
Then qmail was declared on the other hand Qmail was a safe mta but its setting was
difficult.Later it appears including the pealarities of Postfix sendmail and the safety of qmail.
35
To download Postfix to the server
Sudo apt-get install postfix
Listing 5.16 : To download Postfix
To configurate Postfix
Sudo dpkg-configure postfix
Listing 5.17 : Configure the Postfix
When we start postfix after the process of configuration it begins to work and send mail.
Sudo /etc/init.d/postfix restart
Listing 5.18 : Postfix Restart
Writing terminal for testing
$mail –s “test”
Deneme
.
If the mail statement doesn’t work on your computer,you should download apt-get install
mailx package.
5.7 SASL Installation
After postfix is set up,it is set up to confirm their password and users.
Sudo apt-get install libsasl2 sasl2-bin
Listing 5.19 : Setup SASL
36
5.8 Dovecot
Postfix is mta,that is,it is a tool to send a mail.To control over the POP and IMAP.We
need to set up Dovecot to server.Dovecot is very safe server.It present the reinforcement of Pop
and IMAP.The user of mail can hold their mails on the server or if they want,they will download
their mails to their PC.
To set up dovecot as POP and IMAP.
Sudo apt-get intsall dovecot-common dovecot-imapd dovecot-pop3d
Listing 5.20 : Download Dovecot as POP and IMAP
Later /etc/dovecot/dovecot.conf in the scale file
Protocols =pop3 pop3s imap imaps
Pop3_uidl-format=%08Xu%08Xv
Default_mail_env=mbox:~/mail:INBOX
Generally mails hold in the form of Mail.To start dovecot
Sudo /etc/init.d/dovecot restart
Listing 5.21 : Restart Dovecot
If we want,we can add the support of SSL to our server.
Postfix user & password
postfix@localhost
password=555
Listing 5.22 : Connect to Postfix
37
5.9 Installing MySQL map support for Postfix
To install postfix-mysql, install the postfix-mysql package.
To install MySQL client program, install the mysql-client package.
To install MySQL server, install the mysql-server package.
5.10 Installing Packages for Client Access and Authentication
We will need to offer our user IMAP/POP3 access. Our setup will offer those using the
following packages. To provide client authentication, install the courier-authdaemon package.
To add MySQL support for courier-authdaemon, install the courier-authmysql package.
On Ubuntu 7.10, courier-authmysql seems deprecated, install courier-authlib-mysql instead.
To provide unencrypted POP3 access, install the courier-pop package.
To provide SSL-encrypted POP3 access, install the courier-pop-ssl package.
To provide unencrypted IMAP access, install the courier-imap package.
To provide SSL-encrypted IMAP access , install the courier-imap-ssl package.
5.11 Installing package for SMTP authentication
Our system will allow road-warriors to send email through our server using authenticated
SMTP. This will basically stop unauthorized relaying through our mail server. Not only we are
authenticating our user's when they are retrieving mails but also we authenticate them when they
are sending mails as well.
To provide encrypted authenticated SMTP, install the postfix-tls package.
This may have already installed with postfix. If so,leave it.
To install Cyrus SASL library, install the libsasl2 package.
38
To add authentication mechanisms for the SASL library, install the libsasl2-modules package.
To add MySQL support authentication mechanisms with the SASL library, install the libsasl2modules-sql package.
To create certificates, install the openssl package.
5.12 How Postfix Virtual Domains Work?
There are two types of domains in Postfix.

Local domains: All domains which are listed as mydestination are treated as local
domains by Postfix. Emails for local domains are delivered to system users which are
listed in /etc/passwd file and these mails are spooled in /var/mail directory.

Virtual domains: In addition to the local domains Postfix can deliver mails for virtual
domains. Unlike local domains, Postfix will let us handle virtual domains in a very
flexible manner. The good thing with virtual domains is that we do not need system
account in /etc/passwd for each and every mail account. This provides us a way to handle
thousands of mail accounts very easily in our mail server system. The mapping which we
discussed above is used to handle mail account information. You can use MySQL,
PostgreSQL , or LDAP for the user account management. In our setup we use MySQL
backend to manage user accounts of virtual domains. Postfix handles virtual domains as
two different categories and you need to understand how this works[9].
o
Virtual alias domains: These domains are used to forward or alias mails from
one email address to another email address. Such domains can be used receive
mailboxes and store on your hard disk. You do not necessarily need to use virtual
alias domains in your setup. Instead we can user virtual_alias_maps even if the
domains are not listed as virtual alias domains. The virtual_alias_maps is a
general-purpose redirection mapping that works for everything that passes your
system including local domains.
o
Virtual mailbox domains: Postfix uses these domains to receive mails for users
under the domains and store them in the mailboxes on the hard disk. This is
parameter which will simply tell Postfix to receive the mails on behalf of the
39
domain and store them in each user's mailbox. The virtual_mailbox_maps
mapping is used by Postfix to determine the location of the mailbox on your hard
disk. Please remember that you can still use the virtual_alias_maps mapping to
forward email to other mailboxes or external email addresses so not every user on
that domain must actually have a mailbox but can also just have the email
forwarded somewhere else.
5.13 How Postfix Mappings Work?
It is very important to understand how Postfix mapping works. Heart of our system is
Postfix mapping.The generic literal meaning of mapping is assign one value to another. What we
have to map in Postfix is email user accounts or email address. One example is /etc/aliases, the
local aliases or local system users mapping file used by Postfix.
The syntax of this file is: postmaster: root
This makes all the mails which are coming to postmaster@yourdomain are redirected to
root@yourdomain.We can divide the above syntax to Left Hand Side LHS and Right Hand Side
RHS. This RHS and LHS are common abbreviations which we usually used in mappings. The
following table will make this idea even more clear.
LHS
RHS
postmaster: root
With a basic default Postfix installation we use text file for mappings. We write the
mappings into this file and then convert it into a hash file using postmap command so Postfix can
look up items quickly. For example, assume that we need to map our virtual mailboxes in a file
called /etc/Postfix/virtual_mailboxes. The syntax of this file look like:
info@domain1.com
info@domain2.com
Listing 5.23 : /etc/Postfix/virtual_mailboxes
40
You may have noticed that we don't have colon(:) in the LHS of the mappings file
Then you need to run: postmap /etc/postfix/virtual_mailboxes
You can access this mappings in the Postfix configuration file by including the following
line:
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes
In our setup, we will replace this text mapping files with MySQL tables. Our intention is
to make data handling lot more flexible, robust, and scalable. Since database tables can and
usually contain more than just two columns you will need to tell Postfix which database column
is meant to be the LHS and which is the RHS. This is accomplished by creating a configuration
file which will look something like this:
user = postfix
password = example
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions= and active=’1’
Listing 5.24 : /etc/postfix/mysql_virtual_mailbox_maps.cf
For the purposes of this discussion, lets assume this is saved in a file called
/etc/postfix/mysql_virtual_mailbox_maps.cf. You would then be able to use this mapping in
postfix using the following entry in main.cf file.
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
Listing 5.25 : Postfix using entry in mysql_virtual_mailboxes_maps.cf
41
The fields in this configuration file are the user that needs to connect to the MySQL
database, password of that MySQL user, dbname, the name of the MySQL database, table ,the
name of the table in MySQL database and hosts, the name of the server that MySQL runs on
5.14 Setting Postfix MySQL Maps
As specified earlier in this document you need to tell Postfix where the control
information is stored in the database. You need to create the following four text files in
/etc/postfix for that reason.
Note that in the files we create below, we specify 127.0.0.1 for the hosts field instead of
localhost. This is because Postfix is run in a chroot environment, and if you specify localhost
Postfix will try to connct to the MySQL deamon using a unix socket in the directory
/var/run/mysql, to which it will not have access. Using 127.0.0.1 forces Postfix to connect using a
TCP/IP socket, which will work in the chroot environment.
5.14.1 Creating Virtual Alias Maps
Postfix will use this file for Virtual Alias Maps and it will use The LHS of the mapping is
defined as where_field and the RHS is defined as select_field. In this file it would be a mapping
of the address column to the goto column.
$ sudo editor /etc/postfix/mysql_virtual_alias_maps.cf
Listing 5.26 : /etc/postfix/mysql_virtual_alias_maps.cf
Then add the following code segment to the above file.
user = postfix
password = postfixpassword
hosts = 127.0.0.1
dbname = postfix
table = alias
select_field = goto
where_field=address
Listing 5.27 : /etc/postfix/mysql_virtual_alias_maps.cf
42
5.14.2 Virtual Domain Maps
Posfix is only using domain field from this table. For domains we do not need to map
LHS and RHS.
$ sudo editor /etc/postfix/mysql_virtual_domains_maps.cf
Listing 5.28 : /etc/postfix/mysql_virtual_domains_maps.cf
Then add the following code segment to the above file.
user = postfix
password = postfixpassword
hosts = 127.0.0.1
dbname = postfix
table = domain
select_field = domain
where_field = domain
#Additional_conditions=and backupmx=’0’and active=’1’
Listing 5.29 : /etc/postfix/mysql_virtual_domains_maps.cf
5.14.3 Virtual Mailbox Maps
Postfix will map username column with maildir querying mailbox table.
$ sudo editor /etc/postfix/mysql_virtual_mailbox_maps.cf
Listing 5.30 : /etc/postfix/mysql_virtual_mailbox_maps.cf
Then add the following code segment to the above file.
user = postfix
password = postfixpassword
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions=and active=’1’
Listing 5.31 : /etc/postfix/mysql_virtual_mailbox_maps.cf
43
5.14.4 Virtual Mailbox Quota Maps
Postfix will this maps to handle the quota for virtual mailboxes. Username column will be
mapped with the quota column in the mailbox table.
$ sudo editor /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
Listing 5.32 : /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
Then add the following code segment to the above file.
user = postfix
password = postfixpassword
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active=’1’
Listing 5.33 : /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
5.14.5 Relay Domain Maps
If you are going to use your mail system only for hosting backup MX for some virtual
domains then you need this mapping to tell the Postfix to enable the relaying for these domains.
$ sudo editor /etc/postfix/mysql_relay_domains_maps.cf
Listing 5.34 : /etc/postfix/mysql_relay_domains_maps.cf
user = postfix
password = postfixpassword
hosts = 127.0.0.1
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = ‘1’
Listing 5.35 : /etc/postfix/mysql_relay_domains_maps.cf
44
Execute the following commands to make these file secure from others.
To set the group of these files to postfix: $ sudo chgrp postfix /etc/postfix/mysql_*.cf
To make the file readable by the group: $ sudo chmod 640 /etc/postfix/mysql_*.cf
5.15 Configuring Postfix with MySQL maps
We have already created our MySQL maps config files and now the time is to setup
Postfix main.cf file so that Postfix can query MySQL database for virtual mailboxes and
domains.
Open the main.cf file: $ sudo editor /etc/postfix/main.cf
Then add the following code segment to main.cf
# Virtual Mailbox Domain Settings
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit = 51200000
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_transport = virtual
Listing 5.36 : Virtual Mailbox Domain Settings/etc/postfix/main.cf
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps =
mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the your maildir has overdrawn your
diskspace quota, please free up some of spaces of your mailbox try again.
45
virtual_overquota_bounce=yes
Listing 5.37 : Additional for quota support/etc/postfix/main.cf
5.16 Setting up Postfix
Postfix has several hundred configuration parameters that are controlled via the main.cf
file. Fortunately, all parameters have sensible default values. We only have to define the
following parameters.
$ sudo editor /etc/postfix/main.cf
Listing 5.38: Setting up Postfix
#The host name where your MX for virtual domains will point to
myhostname = mail.domain.com
mydestination = #Remains blank since we are going to host virtual domains
relayhost = #Remains blank unless you are going to use your ISP's SMTP server
mail sending out
mails. In which case it would be set to the host name of the ISP's SMTP server
Listing 5.39 : The host name where your MX for virtual domains
Leave the following to their default values
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mynetworks = all
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
Listing 5.40 : Main.cf file
And set up permissions for postfix to use sasl, or you will get error: SASL authentication
failure: cannot connect to saslauthd server: Permission denied.
46
usermod -G sasl postfix
Listing 5.41 : Setup permissions for postfix to use sasl
5.17 Enhanced Mail Services
Install package :
dpkg -i postfixadmin_2.2.1.1_all.deb
Listing 5.42 : Installation of package and postfixadmin
Setup databases :
http://localhost/postfixadmin/setup.php
Listing 5.43 : Setup databases for postfixadmin
Restart apache2 :
/etc/init.d/apache2 restart
Listing 5.44 : Restart apache2
5.18 SMTP Authentication
#smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks,
permit_sasl_authenticated, reject_non_fqdn_recipient,
reject_unknown_recipient_domain reject_unauth_destination,
check_policy_service inet:127.0.0.1:10023, permit
Listing 5.45 : SMTP Authenication
In /etc/postfix/main.cf add
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks,
permit_sasl_authenticated, reject_non_fqdn_recipient,
reject_unknown_recipient_domain reject_unauth_destination,
check_policy_service inet:127.0.0.1:10023, permit
# modify the existing smtpd_sender_restrictions
smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks,
47
reject_non_fqdn_sender, reject_unknown_sender_domain,
reject_unauth_pipelining, permit
# then add these
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_path = /etc/postfix/sasl:/usr/lib/sasl2
smtpd_sasl_security_options = noanonymous
In /etc/postfix/sasl/smtpd.conf
pwcheck_method: auxprop
auxprop_plugin: sql
mech_list: plain login cram-md5 digest-md5
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user: postfix
sql_passwd: yourpassword
sql_database: postfix
Listing 5.46 : In /etc/postfix/sasl/smtpd.conf file for databases
48
CHAPTER VI
PROJECT PROCESS
6.1 Sending a basic mail on localhost
Figure 6.1 : Sending mail on localhost
Firstly via sudo su command admin which is also called root help us to get the authorization.
So it wont ask for authorization in each progress.
After that via /etc/init.d/postfix start commands we start postfix.
After doing it (with the order) we use commands like helo ,mail from, rcpt to.
The basic SMTP commands are:
HELO: Initiates a conversation with the mail server. When using this command you can specify
your domain name so that the mail server knows who you are. For example, HELO localhost.
49
MAIL: Indicates who is sending the mail. For example, MAIL FROM: <root@localhost>.
RCPT: Indicates who is recieving the mail. For example, RCPT TO: <sahin@localhost>.
DATA: Indicates that you are about to send the text (or body) of the message. The message text
must end with the following five letter sequence: "\r\n.\r\n."
QUIT: Indicates that the conversation is over.
MUTT: Mutt is a small but very powerful text based program for reading electronic mail under
UNIX operating systems, including support color terminals, MIME, and a threaded sorting mode.
We make the correctment of mail's cd /var/mail to see the mail which sent to <root@localhost>.
We make Correction with ls -la command as shown in Figure 6.2.
Figure 6.2 : Lists ALL the files and directories in the /var/mail directory
50
Then with using mutt -f sahin command we can get the user (Mail user agent) sahin and see the
mails which is sent for the user Sahin as shown in Figure 6.3 and 6.4.
Figure 6.3 : Looking mail on MUTT
Figure 6.4 : Read mail on MUTT
51
CONCLUSION
Today, PostfixAdmin Configuration Tool has a most important factor for every
department in the all business life also many sectors use the PostfixAdmin Configuration Tool
such as firms, universities, schools. PostfixAdmin system with its easiness, flexibility and
trustworthy its discriminates from the other e-mail representer. If our system will develop
Postfixadmin configuration tool system can be used in different areas.
When we first got this project we didn’t know much about linux and postfixadmin.
However,as we deal with the project we learn new things in time. This project was so helpful for
our own development.
52
REFERENCES
1. Postfix(MTA),https://help.ubuntu.com/community/Postfix
2.
MySQL, user manual http://tangentsoft.net/mysql++/doc/html/userman/
3. Apache, http://www.webopedia.com/TERM/A/Apache_Web_server.html
4. PHP, http://www.wisegeek.com/
5.
phpMyAdmin , http://www.phpmyadmin.net/home_page/index.php
6. MyslWorkbench, http://en.wikipedia.org/wiki/MySQL_Workbench
7. Mozilla Thunderbird, http://en.wikipedia.org/wiki/Mozilla_thunderbird
8. Dovecot, http://en.wikipedia.org/wiki/Dovecot_(software)
9. Posttfix, https://help.ubuntu.com/community/postfixcompletevirtualmailsystemhowto
10. Postfix(MTA), http://www.postfixldap.org
53
Download