Detailed tutorial on installing and configuring Postfix Mail Service on Ubuntu 14.04
Postfix: The mail server used to accept and send mail, the correct statement should be called the Mail Delivery agent (mail Transfer Agent,mta), is the most important part of the mail service;
Dovecot:pop and IMAP server, used to manage the local mail directory so that users can log in and download mail through Mail.app, Thunderbird, Mutt and other mail clients (also called Mail user Agent Mail users agents, MUA);
Postgrey: Mail Gray List tool, can easily resist junk mail;
Amavisd-new: A proxy, used to connect the mail transfer agent and content Checker, can be understood as Postfix the mail to it, it is responsible for contacting virus scanning and spam filtering;
Clam AntiVirus: Virus scanning Tool;
SpamAssassin: Junk e-mail content filtering tool;
Postfix Admin:postfix Web Front-end for managing mail users and domain names.
Set the host name (do not skip this step):
# hostname mail.seniorit.cn
# vi/etc/hosts
127.0.0.1 mail.seniorit.cn localhost
Update system:
$ sudo apt-get update
$ sudo apt-get upgrade
Install the necessary packages
Apt-get Install apache2 mysql-server php5 php-apc php-xml-parser php5-cli php5-common php5-dev php5-curl php5-memcache php 5-GD php-pear php5-imap php5-mcrypt php5-xmlrpc php5-xsl php5-mysql php5-ldap php5-mcrypt php5-cli php-soap php5-json php5 -imap phpMyAdmin
The installation of Lamp,postfix itself does not require apache/php/mysql, but because Postfix admin is installed and the administrative user needs to use the database, apache/php and MySQL are installed.
$ sudo apt-get install lamp-server^
$ sudo apt-get install PHP-APC php5-curl php5-gd php-xml-parser php5-imap
Install the mail server and some tools:
$sudo Apt-get Install mail-server^
$sudo apt-get Install Postfix-mysql dovecot-mysql postgrey-y
$sudo apt-get Install Amavis ClamAV clamav-daemon spamassassin-y
$sudo apt-get Install Libnet-dns-perl Pyzor razor-y
$sudo apt-get Install ARJ bzip2 cabextract cpio file gzip nomarch pax Unzip Zip-y
Configure Apache
After editing the Apache configuration file, restart:
sudo vi/etc/apache2/apache2.conf
Add
ServerName localhost:80
Configure PHP:
Change the expose_php setting In/etc/php5/apache2/php.ini. Set it to "OFF":
expose_php = Off
Add/modify the following settings:
Post_max_size = 32M
Upload_max_filesize = 32M
Memory_limit = 768M
Php5enmod IMAP MCrypt
$ sudo/etc/init.d/apache2 Restart
Configuring the MySQL Database
Create a database named Mail and set permissions and passwords:
$ mysql-uroot-p
Mysql> Create Database Mail;
Mysql> Grant all on mail.* to ' mail ' @ ' localhost ' identified by ' nipc#123 ';
Configure Postfix Admin
Download Psotfixadmin,
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.3.8/postfixadmin-2.3.8.tar.gz
TAR-ZXF postfixadmin-2.3.8.tar.gz
MV Postfixadmin-2.3.8/var/www/html/postfixadmin
Chown-r Www-data:www-data/var/www/html/postfixadmin
Configure Postfixamdin, the standard PHP program configuration method, fill in the information required to access the database, where the Setup_password part is filled in later:
$ sudo vi/var/www/html/postfixadmin/config.inc.php
...
$CONF [' configured '] = true;
$CONF [' setup_password '] = ' replace later ';
$CONF [' postfix_admin_url '] = ' http://mail.seniorit.cn/postfixadmin ';
$CONF [' database_type '] = ' mysql ';
$CONF [' database_host '] = ' localhost ';
$CONF [' database_user '] = ' mail ';
$CONF [' database_password '] = ' nipc#123 ';
$CONF [' database_name '] = ' mail ';
$CONF [' admin_email '] = ' [email protected] ';
$CONF [' encrypt '] = ' md5crypt ';
...
Use the browser to access http://mail.seniorit.cn/postfixadmin/setup.php, substituting the hashed password string for the relevant part of the above $CONF [' setup_password '] = ' later substitution '.
For security reasons, it is best to disable Web Access setup.php:
$ sudo vi/var/www/postfixadmin/.htaccess
<files "setup.php" >
Deny from all
</Files>
Configure Dovecot
Add vmail account to System:
$ sudo useradd-r-u 150-g mail-d/var/vmail-s/sbin/nologin-c "Virtual Mail" Vmail
$ sudo mkdir/var/vmail
$ sudo chmod 770/var/vmail
$ sudo chown vmail:mail/var/vmail
Start configuration Dovecot,dovecot supports a variety of authentication methods, where database authentication is used,
Note the following configuration file one contains one, at first glance a little bit messy,
10-auth.conf has a!include Auth-sql.conf.ext line that will contain/etc/dovecot/conf.d/auth-sql.conf.ext,
And the Auth-sql.conf.ext will contain the/etc/dovecot/dovecot-sql.conf.ext mentioned below,
So as long as the different include can switch different authentication methods, although the first look at a bit more complicated but familiar with the later use is very convenient.
$ sudo vi/etc/dovecot/conf.d/10-auth.conf
Disable_plaintext_auth = yes
Auth_mechanisms = Plain Login
!include Auth-sql.conf.ext
Configure Dovecot to set the database parameters so that Dovecot can properly access the mail database you just created:
$ sudo vi/etc/dovecot/dovecot-sql.conf.ext
...
Driver = MySQL
Connect = host=localhost dbname=mail user=mail password=nipc#123
Default_pass_scheme = Md5-crypt
...
Password_query = \
SELECT username as user, password, '/var/vmail/%d/%n ' as userdb_home, \
' maildir:/var/vmail/%d/%n ' as Userdb_mail, 8 as Userdb_gid \ Userdb_uid
From mailbox WHERE username = '%u ' and active = ' 1 '
User_query = \
SELECT '/var/vmail/%d/%n ' as Home, ' maildir:/var/vmail/%d/%n ' as mail, \
As UID, 8 as GID, concat (' dirsize:storage= ', quota) as quota \
From mailbox WHERE username = '%u ' and active = ' 1 '
...
Where is the user's place on the server to store the mail? So you need to specify the mail address/var/vmail, which was created when the Vmail account was created:
$ sudo vi/etc/dovecot/conf.d/10-mail.conf
...
Mail_location = maildir:/var/vmail/%d/%n
Mail_uid = Vmail
Mail_gid = Mail
...
Modify/etc/dovecot/conf.d/10-master.conf
$ sudo vi/etc/dovecot/conf.d/10-master.conf
...
Service Auth {
Unix_listener Auth-userdb {
mode = 0600
user = Vmail
Group = Mail
}
Unix_listener/var/spool/postfix/private/auth {
mode = 0660
user = Postfix
Group = Postfix
}
...
Confirm that Dovecot has permission to read the configuration file:
$ sudo chown-r vmail:dovecot/etc/dovecot
$ sudo chmod-r o-rwx/etc/dovecot
Configuration Amavis, ClamAV, SpamAssassin
Mutual ClamAV, Amavis users to the other group in order to be able to access each other, configure filtering mode:
$ sudo adduser clamav Amavis
$ sudo adduser amavis ClamAV
$ sudo vi/etc/amavis/conf.d/15-content_filter_mode
Use strict;
@bypass_virus_checks_maps = (
%bypass_virus_checks, @bypass_virus_checks_acl, $bypass _virus_checks_re);
@bypass_spam_checks_maps = (
%bypass_spam_checks, @bypass_spam_checks_acl, $bypass _spam_checks_re);
1; # Ensure a defined return
Enable SpamAssassin:
$ sudo vi/etc/default/spamassassin
...
Enabled=1
Cron=1
...
Configure Postfix
MAIN.CF is the primary configuration file for Postfix:
$ sudo/etc/postfix/main.cf
...
Smtpd_sasl_type = Dovecot
Smtpd_sasl_path = Private/auth
Smtpd_sasl_auth_enable = yes
Myhostname = mail.seniorit.cn
Myorigin =/etc/hostname
mydestination = mail.seniorit.cn, localhost
Mynetworks = 127.0.0.0/8
Inet_interfaces = All
Mynetworks_style = Host
Virtual_mailbox_base =/var/vmail/
Virtual_alias_maps = MYSQL:/ETC/POSTFIX/MYSQL_VIRTUAL_ALIAS_MAPS.CF,
Mysql:/etc/postfix/mysql_virtual_alias_domainaliases_maps.cf
Virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
Mail_spool_directory =/var/mail
Virtual_transport = Dovecot
Dovecot_destination_recipient_limit = 1
Content_filter = amavis:[127.0.0.1]:10024
Header_checks = Regexp:/etc/postfix/header_checks
...
Note that the above is configured with line header_checks = regexp:/etc/postfix/header_checks, we do not have header_checks files, create one and include content, add a bit of privacy to your email, filter some information:
$ sudo vi/etc/postfix/header_checks
/^received:/ IGNORE
/^user-agent:/ IGNORE
/^x-mailer:/ IGNORE
/^x-originating-ip:/ IGNORE
/^x-cr-[a-z]*:/ IGNORE
/^thread-index:/ IGNORE
You also need to configure the MASTER.CF file:
$ sudo vi/etc/postfix/master.cf
...
Smtps inet N----SMTPD
-O Syslog_name=postfix/smtps
-O Smtpd_tls_wrappermode=yes
-O Smtpd_sasl_auth_enable=yes
-O Smtpd_tls_auth_only=yes
-O Smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject
-O Smtpd_sasl_security_options=noanonymous,noplaintext
-O smtpd_sasl_tls_security_options=noanonymous
Amavis Unix----2 SMTP
-O smtp_data_done_timeout=1200
-O Smtp_send_xforward_command=yes
-O Disable_dns_lookups=yes
-O max_use=20
127.0.0.1:10025 inet N----SMTPD
-O content_filter=
-O local_recipient_maps=
-O relay_recipient_maps=
-O smtpd_restriction_classes=
-O Smtpd_delay_reject=no
-O Smtpd_client_restrictions=permit_mynetworks,reject
-O smtpd_helo_restrictions=
-O smtpd_sender_restrictions=
-O Smtpd_recipient_restrictions=permit_mynetworks,reject
-O smtpd_data_restrictions=reject_unauth_pipelining
-O smtpd_end_of_data_restrictions=
-O MYNETWORKS=127.0.0.0/8
-O smtpd_error_sleep_time=0
-O smtpd_soft_error_limit=1001
-O smtpd_hard_error_limit=1000
-O smtpd_client_connection_count_limit=0
-O smtpd_client_connection_rate_limit=0
-O receive_override_options=no_header_body_checks,no_unknown_recipient_checks
Dovecot unix-n N--pipe
Flags=drhu user=vmail:mail argv=/usr/lib/dovecot/dovecot-lda-d $ (recipient)
You also need to configure several files:
$ sudo vi/etc/postfix/mysql_virtual_alias_domainaliases_maps.cf
user = Mail
Password = nipc#123
hosts = 127.0.0.1
dbname = Mail
query = SELECT goto from Alias,alias_domain
WHERE alias_domain.alias_domain = '%d '
and Alias.address=concat ('%u ', ' @ ', alias_domain.target_domain)
and alias.active = 1
$ sudo vi/etc/postfix/mysql_virtual_alias_maps.cf
user = Mail
Password = nipc#123
hosts = 127.0.0.1
dbname = Mail
Table = Alias
Select_field = Goto
Where_field = Address
Additional_conditions = and active = ' 1 '
$ sudo vi/etc/postfix/mysql_virtual_domains_maps.cf
user = Mail
Password = nipc#123
hosts = 127.0.0.1
dbname = Mail
Table = Domain
Select_field = Domain
Where_field = Domain
Additional_conditions = and backupmx = ' 0 ' and active = ' 1 '
$ sudo vi/etc/postfix/mysql_virtual_mailbox_domainaliases_maps.cf
user = Mail
Password = nipc#123
hosts = 127.0.0.1
dbname = Mail
query = SELECT maildir from mailbox, Alias_domain
WHERE alias_domain.alias_domain = '%d '
and Mailbox.username=concat ('%u ', ' @ ', alias_domain.target_domain)
and mailbox.active = 1
$ sudo vi/etc/postfix/mysql_virtual_mailbox_maps.cf
user = Mail
Password = nipc#123
hosts = 127.0.0.1
dbname = Mail
Table = Mailbox
Select_field = CONCAT (domain, '/', Local_part)
Where_field = Username
Additional_conditions = and active = ' 1 '
You are done, restart related services:
$ sudo service spamassassin restart
$ sudo service Clamav-daemon restart
$ sudo service Amavis restart
$ sudo service dovecot restart
$ sudo service postfix restart
Test Postfix
Telnet to the 25 port (SMTP) of the mail server, and then send the HELO mail.seniorit.cn instruction to get the mail.seniorit.cn confirmation:
$ telnet mail.seniorit.cn 25
Trying 192.168.2.66 ...
Connected to mail.seniorit.cn.
Escape character is ' ^] '.
mail.seniorit.cn ESMTP Postfix (Ubuntu)
HELO mail.seniorit.cn
mail.seniorit.cn
Send a message with telnet try the following mail from, RCPT to, DATA,., QUIT are directives:
$ telnet mail.seniorit.cn 25
Trying 192.168.2.66 ...
Connected to mail.seniorit.cn.
Escape character is ' ^] '.
mail.seniorit.cn ESMTP Postfix (Ubuntu)
MAIL From:<[email protected]>
2.1.0 Ok
RCPT To:<[email protected]>
2.1.5 Ok
DATA
354 END data with <CR><LF>.<CR><LF>
SUBJECT:A test Message
This is a test message!
.
2.0.0 ok:queued as 6832ff0036
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
Installing and configuring SquirrelMail
sudo apt-get install SquirrelMail
Configure SquirrelMail
sudo squirrelmail-configure
Everything is pre-configured, we just need to change Organization name.
? Press 1 (Organization Preferences)? Again press 1 (Organization Name)?
Organization Name? Press S? Press Q to quit
Now configure Apache to enable SquirrelMail.
sudo cp/etc/squirrelmail/apache.conf/etc/apache2/sites-available/squirrelmail.conf
sudo a2ensite squirrelmail
sudo service apache2 restart
Now open Http://serverIP/squirrelmail in your browser and login using username
Install postfix on Ubuntu 14.04.txt