Difference between revisions of "Email server setup"

Line 26: Line 26:
 
==MySQL database==
 
==MySQL database==
  
Create a new database and user for email.
+
Create and initialize a new database and user for email.
  
 +
 +
===Create database===
  
 
I assume that:
 
I assume that:
 
* Database name: '''maildb'''
 
* Database name: '''maildb'''
 
* Db user: '''maildb'''
 
* Db user: '''maildb'''
 
 
MySQL script:
 
  
  
Line 49: Line 48:
 
exit;
 
exit;
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
 +
===Schema===
 +
 +
 +
Create the following schema using [[MySQL workbench]]:
 +
 +
<syntaxhighlight lang="sql">
 +
 +
CREATE TABLE `aliases` (
 +
    `pkid` smallint(3) NOT NULL auto_increment,
 +
    `mail` varchar(120) NOT NULL default '',
 +
    `destination` varchar(120) NOT NULL default '',
 +
    `enabled` tinyint(1) NOT NULL default '1',
 +
    PRIMARY KEY (`pkid`),
 +
    UNIQUE KEY `mail` (`mail`) ) ;
 +
 +
CREATE TABLE `domains` (
 +
  `pkid` smallint(6) NOT NULL auto_increment,
 +
  `domain` varchar(120) NOT NULL default '',
 +
  `transport` varchar(120) NOT NULL default 'virtual:',
 +
  `enabled` tinyint(1) NOT NULL default '1',
 +
  PRIMARY KEY (`pkid`) ) ;
 +
 +
CREATE TABLE `users` (
 +
  `id` varchar(128) NOT NULL default '',
 +
  `name` varchar(128) NOT NULL default '',
 +
  `uid` smallint(5) unsigned NOT NULL default '5000',
 +
  `gid` smallint(5) unsigned NOT NULL default '5000',
 +
  `home` varchar(255) NOT NULL default '/var/spool/mail/virtual',
 +
  `maildir` varchar(255) NOT NULL default 'blah/',
 +
  `enabled` tinyint(3) unsigned NOT NULL default '1',
 +
  `change_password` tinyint(3) unsigned NOT NULL default '1',
 +
  `clear` varchar(128) NOT NULL default 'ChangeMe',
 +
  `crypt` varchar(128) NOT NULL default 'sdtrusfX0Jj66',
 +
  `quota` varchar(255) NOT NULL default '',
 +
  PRIMARY KEY (`id`),
 +
  UNIQUE KEY `id` (`id`) ) ;
 +
 +
</syntaxhighlight>
 +
  
  

Revision as of 16:38, 11 August 2014



Overview

Requirements

An email server requires a lot of components:

  • Send / Receive emails [SMTP, POP3, IMAP, ...]
  • Tools to check the email content against virus, spam
  • Tools to encrypt the communication
  • (optional) Database to manage users and emails


Therefore, before going on you need to have:



Installation

MySQL database

Create and initialize a new database and user for email.


Create database

I assume that:

  • Database name: maildb
  • Db user: maildb


# log in as root 
mysql -u root -p 

# Create the mail database 
create database maildb; 

# Create a new user and grant rights upon mail database
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON maildb.* TO 'mail'@'localhost' IDENTIFIED by 'mailPASSWORD'; 
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON maildb.* TO 'mail'@'%' IDENTIFIED by 'mailPASSWORD'; 
exit;


Schema

Create the following schema using MySQL workbench:

CREATE TABLE `aliases` ( 
    `pkid` smallint(3) NOT NULL auto_increment, 
    `mail` varchar(120) NOT NULL default '', 
    `destination` varchar(120) NOT NULL default '', 
    `enabled` tinyint(1) NOT NULL default '1', 
    PRIMARY KEY (`pkid`), 
    UNIQUE KEY `mail` (`mail`) ) ; 

CREATE TABLE `domains` ( 
   `pkid` smallint(6) NOT NULL auto_increment, 
   `domain` varchar(120) NOT NULL default '', 
   `transport` varchar(120) NOT NULL default 'virtual:', 
   `enabled` tinyint(1) NOT NULL default '1', 
   PRIMARY KEY (`pkid`) ) ; 

CREATE TABLE `users` ( 
   `id` varchar(128) NOT NULL default '', 
   `name` varchar(128) NOT NULL default '', 
   `uid` smallint(5) unsigned NOT NULL default '5000', 
   `gid` smallint(5) unsigned NOT NULL default '5000', 
   `home` varchar(255) NOT NULL default '/var/spool/mail/virtual', 
   `maildir` varchar(255) NOT NULL default 'blah/', 
   `enabled` tinyint(3) unsigned NOT NULL default '1', 
   `change_password` tinyint(3) unsigned NOT NULL default '1', 
   `clear` varchar(128) NOT NULL default 'ChangeMe', 
   `crypt` varchar(128) NOT NULL default 'sdtrusfX0Jj66', 
   `quota` varchar(255) NOT NULL default '', 
   PRIMARY KEY (`id`), 
   UNIQUE KEY `id` (`id`) ) ;



SMTP send server

## Security libraries
# SASL is the Simple Authentication and Security Layer, a method for adding authentication support to connection-based protocols.
apt-get install libsasl2-modules libsasl2-modules-sql libgsasl7 libauthen-sasl-cyrus-perl sasl2-bin

# Authentication using MySQL
apt-get install libpam-mysql

## Anti-virus
apt-get install clamav-base libclamav6 clamav-daemon clamav-freshclam

## SPAM killer
apt-get install  spamassassin spamc

## Interface to scan emails for virus & spam
apt-get install amavisd-new

## Utility to SEND emails
apt-get install postfix postfix-mysql 

## Utility to RECEIVE emails
apt-get install courier-base courier-authdaemon courier-authlib-mysql courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl



Sources