email:install_a_full_mail_server
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
email:install_a_full_mail_server [2016/11/11 16:41] – peter | email:install_a_full_mail_server [2019/11/27 21:53] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Email - Install a full mail server ====== | ||
- | ===== Requirements ===== | ||
- | |||
- | * Multiple domains using this for email (e.g. @company.com, | ||
- | * Webmail on your server (for anyone in the org to access email). | ||
- | * Aliases / redirects for some email addresses (e.g. so you can redirect " | ||
- | * DO NOT create "linux users" for every email user – it’s a huge security hole, and a massive pain in the ass for the sysadmin. | ||
- | * DO NOT do mail-relaying. | ||
- | |||
- | ===== What is needed ===== | ||
- | |||
- | * Web server [Nginx] | ||
- | * Database server (MySQL) | ||
- | * Email server (MTA) (Exim4) | ||
- | * IMAP server (Dovecot) | ||
- | * Webmail server (Roundcube) | ||
- | |||
- | |||
- | The database server will be used to manage ALL logins and usernames/ | ||
- | |||
- | |||
- | ===== Installation ===== | ||
- | |||
- | You need to install ALL of: | ||
- | |||
- | * apt-get install apache2-mpm-prefork\\ (Some of these email servers require PHP; PHP is crappy and requires mpm-prefork (the ' | ||
- | * apt-get install mysql-client\\ (should auto-install something like: mysql-common + mysql-client-5.5) | ||
- | * apt-get install mysql-server\\ (should auto-install something like: mysql-server-5.5 + mysql-server-core-5.5) | ||
- | * apt-get install exim4 | ||
- | * apt-get install exim4-base | ||
- | * apt-get install exim4-config | ||
- | * apt-get install exim4-daemon-heavy\\ (there' | ||
- | * apt-get install dovecot-core | ||
- | * apt-get install dovecot-imapd | ||
- | * apt-get install dovecot-mysql | ||
- | * apt-get install roundcube | ||
- | * apt-get install roundcube-core | ||
- | * apt-get install roundcube-mysql | ||
- | |||
- | |||
- | ===== Setup: DNS ===== | ||
- | |||
- | You need an " | ||
- | |||
- | |||
- | ===== Setup: Web server ===== | ||
- | |||
- | Roundcube sets up an over-the-top config: it creates an email server on every single website hosted on your server, and makes them all available at once. | ||
- | |||
- | Following the idea of http:// | ||
- | |||
- | |||
- | ==== Create a web address for your webmail ==== | ||
- | |||
- | If you have multiple websites hosted on your server, you SHOULD have a separate file for each inside / | ||
- | |||
- | * / | ||
- | * / | ||
- | * / | ||
- | |||
- | For each domain that you want to give webmail to, edit the file and ADD the following: | ||
- | |||
- | |||
- | <file apache> | ||
- | < | ||
- | ServerName webmail.[the domain name] | ||
- | DocumentRoot / | ||
- | </ | ||
- | </ | ||
- | |||
- | Note: replace “[the domain name]” with the domain name, e.g. " | ||
- | |||
- | |||
- | ===== Setup: create databases ===== | ||
- | |||
- | Create your databases. From the command-line, | ||
- | |||
- | <code bash> | ||
- | mysql -u root -p | ||
- | </ | ||
- | |||
- | …or use your preferred softare (e.g. phpMyAdmin). | ||
- | |||
- | ==== Create the database ==== | ||
- | |||
- | <code mysql> | ||
- | CREATE DATABASE email_accounts; | ||
- | </ | ||
- | |||
- | ==== Create the tables for email-accounts and config ==== | ||
- | |||
- | <code mysql> | ||
- | USE email_accounts; | ||
- | |||
- | CREATE TABLE mailboxes ( | ||
- | id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
- | domain_id INT(10) NOT NULL, | ||
- | local_part VARCHAR(250) NOT NULL, | ||
- | password VARCHAR(100) NULL, | ||
- | description VARCHAR(250) NULL, | ||
- | active TINYINT(1) NOT NULL DEFAULT 0, | ||
- | created TIMESTAMP NOT NULL DEFAULT NOW(), | ||
- | modified TIMESTAMP NULL | ||
- | ); | ||
- | CREATE TABLE aliases ( | ||
- | id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
- | domain_id INT(10) NOT NULL, | ||
- | local_part VARCHAR(250) NOT NULL, | ||
- | goto VARCHAR(250) NOT NULL, | ||
- | description VARCHAR(250) NULL, | ||
- | active TINYINT(1) NOT NULL DEFAULT 0, | ||
- | created TIMESTAMP NOT NULL DEFAULT NOW(), | ||
- | modified TIMESTAMP NULL | ||
- | ); | ||
- | CREATE TABLE vacations ( | ||
- | id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
- | mailbox_id INT(10) NOT NULL, | ||
- | subject VARCHAR(250) NOT NULL, | ||
- | body TEXT NOT NULL, | ||
- | description VARCHAR(250) NULL, | ||
- | active TINYINT(1) NOT NULL DEFAULT 0, | ||
- | created TIMESTAMP NOT NULL DEFAULT NOW(), | ||
- | modified TIMESTAMP NULL | ||
- | ); | ||
- | |||
- | CREATE TABLE domains ( | ||
- | id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
- | fqdn VARCHAR(250) NOT NULL, | ||
- | type ENUM(' | ||
- | description VARCHAR(250) NULL, | ||
- | active TINYINT(1) NOT NULL DEFAULT 0, | ||
- | created TIMESTAMP NOT NULL DEFAULT NOW(), | ||
- | modified TIMESTAMP NULL | ||
- | ); | ||
- | </ | ||
- | |||
- | ==== Create a database-account to access the database ==== | ||
- | |||
- | <code mysql> | ||
- | grant ALL on email_accounts.* to ' | ||
- | flush privileges; | ||
- | </ | ||
- | |||
- | Note: that is not an email address, it’s a MySQL user account. | ||
- | Note: this account will ONLY be accessible by our software running on the server; you cannot access this account remotely (over the internet). | ||
- | |||
- | |||
- | ==== Create your first email account and domain ==== | ||
- | |||
- | |||
- | <code mysql> | ||
- | INSERT INTO domains VALUES(NULL,' | ||
- | INSERT INTO mailboxes VALUES(NULL, | ||
- | </ | ||
- | |||
- | Note: this password is used over the internet when you login to webmail – so pick a good one! This has to be secure! | ||
- | |||
- | ==== Create a redirector for an email address ==== | ||
- | |||
- | <code mysql> | ||
- | INSERT INTO aliases VALUES (NULL, 1, ' | ||
- | </ | ||
- | |||
- | Note: only set this up if you actually want a redirect. | ||
- | |||
- | |||
- | ===== Setup: Configure Exim4 ===== | ||
- | |||
- | When you install Exim4, make sure you chose the “split” packages. If not, you can fix that now by running: | ||
- | |||
- | <code bash> | ||
- | dpkg-reconfigure exim4-config | ||
- | </ | ||
- | |||
- | |||
- | ==== Debian: set the global / initial Exim config ==== | ||
- | |||
- | NB: these are the settings filled out by “dpkg-reconfigure exim4-config”. Here’s what your file should look like: | ||
- | |||
- | Edit: / | ||
- | |||
- | <file bash / | ||
- | # / | ||
- | # | ||
- | # Edit this file and / | ||
- | # yourself or use ' | ||
- | # | ||
- | # Please note that this is _not_ a dpkg-conffile and that automatic changes | ||
- | # to this file might happen. The code handling this will honor your local | ||
- | # changes, so this is usually fine, but will break local schemes that mess | ||
- | # around with multiple versions of the file. | ||
- | # | ||
- | # update-exim4.conf uses this file to determine variable values to generate | ||
- | # exim configuration macros for the configuration file. | ||
- | # | ||
- | # Most settings found in here do have corresponding questions in the | ||
- | # Debconf configuration, | ||
- | # | ||
- | # This is a Debian specific file | ||
- | |||
- | dc_eximconfig_configtype=' | ||
- | dc_other_hostnames=' | ||
- | dc_local_interfaces=' | ||
- | dc_readhost='' | ||
- | dc_relay_domains='' | ||
- | dc_minimaldns=' | ||
- | dc_relay_nets='' | ||
- | dc_smarthost='' | ||
- | CFILEMODE=' | ||
- | dc_use_split_config=' | ||
- | dc_hide_mailname='' | ||
- | dc_mailname_in_oh=' | ||
- | dc_localdelivery=' | ||
- | </ | ||
- | |||
- | Note: replace “[YOUR DOMAIN 1]” with e.g. “my-company.com”, | ||
- | Note: replace “[PUT YOUR SERVER’s IP ADDRESS HERE]” with e.g. “10.0.0.1” (whatever your public internet address is) | ||
- | |||
- | |||
- | ==== Setup Exim: Macros ==== | ||
- | |||
- | ADD the following to / | ||
- | |||
- | <file bash> | ||
- | MAIN_LOCAL_DOMAINS = @: | ||
- | </ | ||
- | |||
- | ADD the following to / | ||
- | |||
- | <file bash> | ||
- | # List of domains considered local for exim. Domains not listed here | ||
- | # need to be deliverable remotely. | ||
- | domainlist local_domains = MAIN_LOCAL_DOMAINS | ||
- | |||
- | # MySQL because exim4 on Debian doesn' | ||
- | |||
- | MYSQL_SERVER=127.0.0.1 | ||
- | MYSQL_DB=email_accounts | ||
- | MYSQL_USER=email | ||
- | MYSQL_PASSWORD=password | ||
- | hide mysql_servers = MYSQL_SERVER/ | ||
- | </ | ||
- | |||
- | |||
- | ===== References ===== | ||
- | |||
- | |||
- | http:// | ||
- | |||
- | https:// | ||
- | |||
- | http:// | ||
- | |||
- | http:// |
email/install_a_full_mail_server.1478882465.txt.gz · Last modified: 2020/07/15 09:30 (external edit)