Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2475,"date":"2019-12-05T00:55:49","date_gmt":"2019-12-05T00:55:49","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2475"},"modified":"2019-12-11T00:37:52","modified_gmt":"2019-12-11T00:37:52","slug":"simple-mailserver-with-postfix-dovecot-and-sieve-on-debian-7","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/simple-mailserver-with-postfix-dovecot-and-sieve-on-debian-7\/","title":{"rendered":"Simple Mailserver With Postfix, Dovecot, And Sieve On Debian 7"},"content":{"rendered":"

The following tutorial describes how to set up a simple mailserver using Postfix as MTA, Dovecot as MDA<\/strong>\u00a0and the awesome Sieve for sorting mails. The starting point is a\u00a0freshly installed server with Debian<\/strong>\u00a0on which you have got either access to the administrative user or sudo rights.<\/p>\n

First, install the necessary packages:<\/strong><\/p>\n

sudo apt-get install postfix dovecot-imapd dovecot-managesieved\r\n<\/code><\/pre>\n

During the installation process,<\/strong>\u00a0you will be asked\u00a0what sort of server<\/strong>\u00a0you are running and\u00a0how Postfix will receive send and receive mails.<\/strong>\u00a0Select “Internet Site<\/strong>” here.<\/p>\n

The first configuration step<\/strong>\u00a0is to\u00a0connect Dovecot with Postfix<\/strong>\u00a0and setup up a postmaster address, this is the address that others will see when mail delivery failed, so they can contact you on eventual problems on your end. Open\u00a0\/etc\/dovecot\/conf.d\/15-lda.conf<\/code>\u00a0and edit the following line:<\/p>\n

postmaster_address = yourname@yourdomain.tld\r\n<\/code><\/pre>\n

In the same file,\u00a0also activate the automatic creation and subscription<\/strong>\u00a0to folders you generate via IMAP:<\/p>\n

lda_mailbox_autocreate = yes\r\nlda_mailbox_autosubscribe = yes\r\n<\/code><\/pre>\n

The next step is to configure the spot<\/strong>\u00a0on the filesystem where the\u00a0mails should be stored<\/strong>. Open\u00a0\/etc\/dovecot\/conf.d\/10-mail.conf<\/code>\u00a0and\u00a0edit the following lines:<\/strong><\/p>\n

mail_location = maildir:~\/Maildir\r\n<\/code><\/pre>\n

Make sure that every other mention<\/strong>\u00a0of\u00a0mail_location<\/code>\u00a0is commented out in this context.\u00a0Now you can tell Postfix<\/strong>\u00a0to hand\u00a0over incoming mails to Dovecot<\/strong>\u00a0by editing\u00a0\/etc\/postfix\/main.cf<\/code>, adding the following line:<\/p>\n

mailbox_command = \/usr\/lib\/dovecot\/deliver\r\n<\/code><\/pre>\n

After restarting both services …<\/strong><\/p>\n

sudo service postfix restart\r\nsudo service dovecot restart\r\n<\/code><\/pre>\n

… you can test if everything is working by issuing the following command:<\/strong><\/p>\n

echo \"Testmail!\" | mail -s \"Testmail!\" root@localhost\r\n<\/code><\/pre>\n

If\u00a0everything is working properly<\/strong>\u00a0you should\u00a0find a message similar<\/strong>\u00a0to the following one in\u00a0\/var\/log\/mail.log<\/code>:<\/p>\n

install postfix\/local[10309]: A0B361DDA2: to=<root@localhost>, relay=local, delay=0.02, delays=0.01\/0\/0\/0.01, dsn=2.0.0, status=sent (delivered to command: \/usr\/lib\/dovecot\/deliver\r\n<\/code><\/pre>\n

Now that the basic service is working<\/strong>, there are two important things left to set up.\u00a0The internet is (sadly) not a friendly place<\/strong>, making encrypting as much as possible a necessity, in this\u00a0case provided by SSL\/TLS<\/strong>. Ideally you would have a\u00a0certificate from a trusted CA<\/strong>\u00a0– such as for example\u00a0StartSSL<\/a><\/strong>\u00a0where you can get a certificate for free<\/strong>\u00a0– but for solely private usage a\u00a0self-signed certificate is fine too<\/strong>. You can generate a self-signed certificate with the following command:<\/p>\n

sudo mkdir \/etc\/dovecot\/private\r\nsudo openssl req -newkey rsa:4096 -sha512 -x509 -days 365 -nodes -keyout \/etc\/dovecot\/private\/mykey.key -out \/etc\/dovecot\/mycert.pem\r\nsudo chmod 600 \/etc\/dovecot\/private\/*\r\n<\/code><\/pre>\n

Depending on the speed of your server CPU<\/strong>, this will take a minute.\u00a0After the generation process is complete<\/strong>, you can\u00a0enable TLS-encryption for both Postfix and Dovecot<\/strong>. For Postfix, add the following lines to\u00a0\/etc\/postfix\/main.cf<\/code>:<\/p>\n

smtpd_tls_cert_file = \/etc\/dovecot\/private\/mykey.pem\r\nsmtpd_tls_key_file = \/etc\/dovecot\/private\/mycert.pem\r\nsmtpd_use_tls = yes\r\n<\/code><\/pre>\n

For Dovecot, open<\/strong>\u00a0\/etc\/dovecot\/conf.d\/10-ssl.conf<\/code>\u00a0and edit the\u00a0SSL-related<\/strong>\u00a0lines:<\/p>\n

ssl = yes\r\nssl_key = \/etc\/dovecot\/private\/mykey.pem\r\nssl_cert = \/etc\/dovecot\/private\/mycert.pem\r\n<\/code><\/pre>\n

Once again, restart both services:<\/strong><\/p>\n

sudo service postfix restart\r\nsudo service dovecot restart\r\n<\/code><\/pre>\n

To verify that the setup is correct<\/strong>, you can test that the\u00a0mailserver allows encrypted connections<\/strong>\u00a0with the following command:<\/p>\n

openssl s_client -starttls smtp -crlf -connect youripaddressoryourdomain:25\r\n<\/code><\/pre>\n

If the\u00a0answer contains both certificate<\/strong>\u00a0and connection information,\u00a0then everything is working properly.<\/strong>\u00a0The last step of\u00a0this tutorial is the configuration<\/strong>\u00a0of\u00a0Sieve<\/strong>. It’s pretty simple, open\u00a0\/etc\/dovecot\/conf.d\/15-lda.conf<\/code>\u00a0with your favorite text editor and edit the following line:<\/p>\n

mail_plugins = $mail_plugins sieve\r\n<\/code><\/pre>\n

A final restart of Dovecot finishes your setup:<\/strong><\/p>\n

sudo service dovecot restart\r\n<\/code><\/pre>\n

At this point, you may want to set up a another user since using root for sending mails is considered arrogant. Simply run:<\/strong><\/p>\n

 useradd -m yourusername\r\n passwd yourusername\r\n<\/code><\/pre>\n

Now you can log into your server as your freshly created user over a secure connection<\/strong>, send and receive mail over secure connections, and\u00a0sort your mails<\/strong>\u00a0with sieve over a secure connection.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[233,244],"manual_kb_tag":[306,307,308],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2475"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2475"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2475\/revisions"}],"predecessor-version":[{"id":2476,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2475\/revisions\/2476"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2475"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2475"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}