{"id":122,"date":"2015-06-14T12:29:51","date_gmt":"2015-06-14T12:29:51","guid":{"rendered":"http:\/\/star.genuinewebhost.com\/~linuxguru\/tutorial\/?p=122"},"modified":"2025-07-10T01:32:04","modified_gmt":"2025-07-10T01:32:04","slug":"configuring-postfix-virtual-mail-domain","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=122","title":{"rendered":"Configuring postfix virtual mail domain"},"content":{"rendered":"<p>This is part of the Postfix documents series, continuation of &#8220;Accessing a dovecot imap server using SquirrelMail&#8221;. One should complete the initial steps in these docuemtns to make this work.<\/p>\n<p>Create a user to manage postfix<br \/>\n<strong>]# useradd postfixuser<\/strong><\/p>\n<p>Find the GID and UID.<\/p>\n<p><strong>]# cat \/etc\/passwd | grep postfixuser<\/strong><br \/>\npostfixuser:x:1003:1003::\/home\/postfixuser:\/bin\/bash<\/p>\n<p><strong>]# cat \/etc\/group | grep postfixuser<\/strong><br \/>\npostfixuser:x:1003:<\/p>\n<p>In my example the UID and GID of the user postfixuser is 1002.<\/p>\n<p>Edit the main config file.<br \/>\n<strong>]# vi \/etc\/postfix\/main.cf<\/strong><\/p>\n<p>Add the below lines:<\/p>\n<p><em>virtual_mailbox_domains = \/etc\/postfix\/vhosts<\/em><br \/>\n<em>virtual_mailbox_base = \/home\/postfixuser<\/em><br \/>\n<em>virtual_mailbox_maps = hash:\/etc\/postfix\/vmaps<\/em><br \/>\n<em>virtual_minimum_uid = 1000<\/em><br \/>\n<em>virtual_uid_maps = static:1003<\/em><br \/>\n<em>virtual_gid_maps = static:1003<\/em><\/p>\n<p>List the domains that you wish to host.<br \/>\n<strong>]# vi \/etc\/postfix\/vhosts<\/strong><br \/>\nAdd the following lines listing examples of domains:<\/p>\n<p><em>mydomain_1.com<\/em><br \/>\n<em>mydomain_2.com<\/em><\/p>\n<p>We should create a file that maps where the mails of each user in each domain will be hosted:<br \/>\n<strong>]# vi \/etc\/postfix\/vmaps<\/strong><\/p>\n<p><em>user1@mydomain_1.com mydomain_1.com\/user1<span style=\"color: #ff0000;\"><strong>\/<\/strong><\/span><\/em><br \/>\n<em>user2@mydomain_1.com mydomain_1.com\/user2<span style=\"color: #ff0000;\"><strong>\/<\/strong><\/span><\/em><br \/>\n<em>user1@mydomain_2.com mydomain_2.com\/user1<strong>\/<\/strong><\/em><br \/>\n<em>user2@mydomain_2.com mydomain_2.com\/user2<span style=\"color: #ff0000;\"><strong>\/<\/strong><\/span><\/em><br \/>\nNow we need to convert the vmaps text file into a hash file by running the following command:<br \/>\n<strong>]# postmap \/etc\/postfix\/vmaps<\/strong><\/p>\n<p>Create folders for each domain in the \/home\/postfixuser folder<\/p>\n<p><strong>]#\u00a0mkdir \/home\/postfixuser\/mydomain_1.com<\/strong><\/p>\n<p><strong>]#\u00a0mkdir \/home\/postfixuser\/mydomain_2.com<\/strong><\/p>\n<p>For testing let us five the folder permission as chmod 777<\/p>\n<p><strong>]# chmod 777 \/home\/postfixuser\/*<\/strong><\/p>\n<p>Restart the postfix server<br \/>\n<strong>]# systemctl restart postfix<\/strong><\/p>\n<p>Now let us send a mail to one of the user using a telnet session:<\/p>\n<p><strong>]# telnet localhost 25<\/strong><br \/>\n<em>Trying ::1&#8230;<\/em><br \/>\n<em>Connected to localhost.<\/em><br \/>\n<em>Escape character is &#8216;^]&#8217;.<\/em><br \/>\n<em>220 &lt;My FDQN&gt; ESMTP Postfix<\/em><br \/>\n<em>EHLO &lt;My FDQN&gt;<\/em><br \/>\n<em>250-&lt;My FDQN&gt;<\/em><br \/>\n<em>250-PIPELINING<\/em><br \/>\n<em>250-SIZE 10240000<\/em><br \/>\n<em>250-VRFY<\/em><br \/>\n<em>250-ETRN<\/em><br \/>\n<em>250-ENHANCEDSTATUSCODES<\/em><br \/>\n<em>250-8BITMIME<\/em><br \/>\n<em>250 DSN<\/em><br \/>\n<em>MAIL FROM:root@&lt;My FDQN&gt;<\/em><br \/>\n<em>250 2.1.0 Ok<\/em><br \/>\n<em>RCPT TO:user2@mydomain_1.com<\/em><br \/>\n<em>250 2.1.5 Ok<\/em><br \/>\n<em>DATA<\/em><br \/>\n<em>354 End data with &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;<\/em><br \/>\n<em>Subject:Hello there<\/em><br \/>\n<em>This is Shiju<\/em><br \/>\n<em>.<\/em><br \/>\n<em>250 2.0.0 Ok: queued as 7E68A6D409E2<\/em><br \/>\n<em>quit<\/em><br \/>\n<em>221 2.0.0 Bye<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Now check if the files got created in the user&#8217;s name<\/p>\n<p><strong>]# ls -l \/home\/postfixuser\/mydomain_1.com\/<\/strong><br \/>\n<em>-rw&#8212;&#8212;- 1 postfixuser postfixuser 565 Sep 14 18:40\u00a0user2<\/em><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This is part of the Postfix documents series, continuation of &#8220;Accessing a dovecot imap server using SquirrelMail&#8221;. One should complete the initial steps in these <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=122\" title=\"Configuring postfix virtual mail domain\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1819,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-postfix"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=122"}],"version-history":[{"count":28,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":884,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions\/884"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/1819"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}