<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.zhouba.cz/index.php?action=history&amp;feed=atom&amp;title=ZhoubaWiki%3AHowToSetupImapServer</id>
	<title>ZhoubaWiki:HowToSetupImapServer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.zhouba.cz/index.php?action=history&amp;feed=atom&amp;title=ZhoubaWiki%3AHowToSetupImapServer"/>
	<link rel="alternate" type="text/html" href="https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:HowToSetupImapServer&amp;action=history"/>
	<updated>2026-04-04T06:54:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:HowToSetupImapServer&amp;diff=11&amp;oldid=prev</id>
		<title>Garak: Created page with &quot;&lt;!-- Category section --&gt; Category:Bugweis &lt;!-- Contents --&gt; {| align=&quot;right&quot;  | __TOC__  |} '''How to set up an incoming email server'''&lt;br&gt;&lt;br&gt; Here is a guide on gettin...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:HowToSetupImapServer&amp;diff=11&amp;oldid=prev"/>
		<updated>2021-05-22T16:20:07Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;!-- Category section --&amp;gt; &lt;a href=&quot;/index.php?title=Category:Bugweis&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Bugweis (page does not exist)&quot;&gt;Category:Bugweis&lt;/a&gt; &amp;lt;!-- Contents --&amp;gt; {| align=&amp;quot;right&amp;quot;  | __TOC__  |} &amp;#039;&amp;#039;&amp;#039;How to set up an incoming email server&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; Here is a guide on gettin...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;!-- Category section --&amp;gt;&lt;br /&gt;
[[Category:Bugweis]]&lt;br /&gt;
&amp;lt;!-- Contents --&amp;gt;&lt;br /&gt;
{| align=&amp;quot;right&amp;quot;&lt;br /&gt;
 | __TOC__&lt;br /&gt;
 |}&lt;br /&gt;
'''How to set up an incoming email server'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Here is a guide on getting incoming email services running on Ubuntu using Postfix. This tutorial has been tested on Ubuntu 12.04. Please keep in mind that you have to be logged as root during the whole process.&lt;br /&gt;
&lt;br /&gt;
== Postfix ==&lt;br /&gt;
&lt;br /&gt;
Let’s get core email functionality going with Postfix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aptitude install postfix&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked a few questions. Unfortunately, the graphical configuration interface that was automatically launched was a condensed version. Confirm the defaults and run the full graphical configuration utility.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dpkg-reconfigure postfix&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, you will be asked some questions:&lt;br /&gt;
&lt;br /&gt;
* General type of mail configuration: '''Internet Site'''&lt;br /&gt;
* System mail name: '''mail.hostname.tld''' ''(Use the identity domain and replace the prefix as necessary)''&lt;br /&gt;
* Root and postmaster mail recipient: ''Leave blank'' (... or use your account name if you want to receive error reports)&lt;br /&gt;
* Other destinations to accept mail for: '''hostname.tld, localhost''' ''(Use the identity domain)''&lt;br /&gt;
* Force synchronous updates on mail queue: '''No'''&lt;br /&gt;
* Local networks: ''leave default''&lt;br /&gt;
* Use procmail for local delivery: '''Yes'''&lt;br /&gt;
* Mailbox size limit (bytes): '''0'''&lt;br /&gt;
* Local address extension character? ''leave default''&lt;br /&gt;
* Internet protocols to use: '''all'''&lt;br /&gt;
&lt;br /&gt;
One more tweak to finish Postfix configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
postconf -e 'home_mailbox = Maildir/'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dovecot ==&lt;br /&gt;
&lt;br /&gt;
Dovecot can act both as an IMAP server and a POP3 server with or without SSL. We will use secured versions of both protocols only. Install the package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aptitude install dovecot-imapd dovecot-pop3d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use IMAP and POP3 over SSL we need to create an SSL certificate to use with Dovecot. We'll use a self-signed certificate since this is not a public server and we would probably have a hard time getting a proper certificate from a trusted source. First we generate a private key for the certificate and make it readable only by root, and then we create the certificate itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openssl genrsa -out /etc/ssl/private/dovecot.key 2048&lt;br /&gt;
chmod 400 /etc/ssl/private/dovecot.key&lt;br /&gt;
openssl req -new -x509 -key /etc/ssl/private/dovecot.key -out /etc/ssl/certs/dovecot.pem -days 1095&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example input:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Country Name (2 letter code) [AU]:GB&lt;br /&gt;
State or Province Name (full name) [Some-State]:&lt;br /&gt;
Locality Name (eg, city) []:London&lt;br /&gt;
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Hostname&lt;br /&gt;
Organizational Unit Name (eg, section) []:&lt;br /&gt;
Common Name (eg, YOUR name) []:mail.hostname.tld&lt;br /&gt;
Email Address []:admin@hostname.tld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure to provide the actual domain name of your mail server, e.g. mail.hostname.tld, when asked about the “Common Name”. Otherwise email clients will complain every time they connect to the server. Since this is a self-signed certificate not backed by a Certification Authority clients will complain the first time anyway, but if you save the certificate subsequent connects will go through silently.&lt;br /&gt;
&lt;br /&gt;
'''(For Ubuntu 11 and older)'''&lt;br /&gt;
&lt;br /&gt;
Edit the configuration file &amp;lt;code&amp;gt;/etc/dovecot/dovecot.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
protocols = imaps pop3s&lt;br /&gt;
mail_location = maildir:~/Maildir&lt;br /&gt;
disable_plaintext_auth = yes&lt;br /&gt;
ssl_cert_file = /etc/ssl/certs/dovecot.pem&lt;br /&gt;
ssl_key_file = /etc/ssl/private/dovecot.key&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''(For Ubuntu 12 and newer)'''&lt;br /&gt;
&lt;br /&gt;
Edit the configuration file &amp;lt;code&amp;gt;/etc/dovecot/conf.d/10-mail.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mail_location = maildir:~/Maildir&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the configuration file &amp;lt;code&amp;gt;/etc/dovecot/conf.d/10-auth.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
disable_plaintext_auth = yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the configuration file &amp;lt;code&amp;gt;/etc/dovecot/conf.d/10-ssl.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl_cert = &amp;lt;/etc/ssl/certs/dovecot.pem&lt;br /&gt;
ssl_key = &amp;lt;/etc/ssl/private/dovecot.key&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart Dovecot with the new config:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo /etc/init.d/dovecot restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Whitelist / Blacklist by sender ==&lt;br /&gt;
&lt;br /&gt;
'''OPEN''' &amp;lt;code&amp;gt;/etc/postfix/main.cf&amp;lt;/code&amp;gt; and add a rule (the rule must be somewhere top that it be processed first):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next '''CREATE''' &amp;lt;code&amp;gt;/etc/postfix/sender_access&amp;lt;/code&amp;gt;&lt;br /&gt;
*There insert the domains which you want ban/allow.&lt;br /&gt;
*'''Example:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user1@hostname.tld	   REJECT&lt;br /&gt;
user2@hostname.tld	   OK&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you must rehash file for create dtb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
postmap /etc/postfix/sender_access&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart postfix:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/postfix restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Script for add a banned domain to sender_access ===&lt;br /&gt;
&lt;br /&gt;
'''CREATE''' &amp;lt;code&amp;gt;/usr/local/bin/addtoblacklist&amp;lt;/code&amp;gt; and insert this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
if grep  -q &amp;quot;$1&amp;quot; /etc/postfix/sender_access; then&lt;br /&gt;
		echo &amp;quot;$1 already on sender_access&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
		echo &amp;quot;$1\tREJECT&amp;quot; &amp;gt;&amp;gt; /etc/postfix/sender_access&lt;br /&gt;
		postmap /etc/postfix/sender_access&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example for adding domain:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
addtoblacklist user1@hostname.tld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Script for add an allowed domain to sender_access ===&lt;br /&gt;
&lt;br /&gt;
'''CREATE''' &amp;lt;code&amp;gt;/usr/local/bin/addtowhitelist&amp;lt;/code&amp;gt; and insert this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
if grep  -q &amp;quot;$1&amp;quot; /etc/postfix/sender_access; then&lt;br /&gt;
		echo &amp;quot;$1 already on sender_access&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
		echo &amp;quot;$1\tOK&amp;quot; &amp;gt;&amp;gt; /etc/postfix/sender_access&lt;br /&gt;
		postmap /etc/postfix/sender_access&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example for adding domain:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
addtowhitelist user1@hostname.tld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done!&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Test is very simply. You can sent test-mail to &amp;lt;code&amp;gt;user@[IP address for mail-server]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
After sending the mail you just check Maildir of the user. If there is a new email, mail-server is works well.&lt;/div&gt;</summary>
		<author><name>Garak</name></author>
	</entry>
</feed>