At this point the /var/vmail directory should be empty yet. You can get a list of all files and directories within by running:
find /var/vmail
There is probably nothing except perhaps a "lost+found" directory if /var/vmail is on a seperate partition.
Let's now try to send an email to the user john@example.org:
echo test | mail john@example.org
If everything worked as expected Postfix has accepted the email and forwarded it to Dovecot which in turn wrote the email in John's maildir. Look again:
find /var/vmail
You should see something like:
/var/vmail/
/var/vmail/example.org
/var/vmail/example.org/john
/var/vmail/example.org/john/Maildir
/var/vmail/example.org/john/Maildir/dovecot-uidvalidity
/var/vmail/example.org/john/Maildir/tmp
/var/vmail/example.org/john/Maildir/dovecot.index.log
/var/vmail/example.org/john/Maildir/dovecot-uidlist
/var/vmail/example.org/john/Maildir/dovecot-uidvalidity.4daa0b32
/var/vmail/example.org/john/Maildir/new
/var/vmail/example.org/john/Maildir/new/1302989618.M190758P1940.debian,S=376,W=386
/var/vmail/example.org/john/Maildir/cur
Your files may have slightly different numbers. So John has a new email in his inbox. Your /var/log/mail.log will look something like:
postfix/pickup[1788]: 2A907A8C: uid=0 from=<root>
postfix/cleanup[1936]: 2A907A8C: message-id=<20110416213338.2A907A8C@myserver>
postfix/qmgr[1789]: 2A907A8C: from=<root@myserver>, size=306, nrcpt=1 (queue active)
dovecot: deliver(john@example.org): msgid=<20110416213338.2A907A8C@myserver>: saved mail to INBOX
postfix/pipe[1939]: 2A907A8C: to=<john@example.org>, relay=dovecot, delay=0.03, delays=0.02/0/0/0.01, dsn=2.0.0, status=sent (delivered via dovecot service)
postfix/qmgr[1789]: 2A907A8C: removed
If anything went wrong then carefully check the last lines of your /var/log/mail.log. It will very likely point you to the problem.
(If you are curious how to send an email to your mail server using a manual SMTP session then read the respective section in the Lenny tutorial. It's also good as an additional test because the "mail" command bypasses a few of Postfix's security features.)
Access the email on disk
Apparently everything went well. To read the email from John's inbox you can use either POP3, IMAP or access the maildir directly. The latter can be done using the console-based "mutt" email client:
mutt -f /var/vmail/example.org/john/Maildir
(You may get asked to create /root/Mail - this is standard procedure. Just answer "yes" or press Enter.)
What you see now are the contents of John's mailbox:

Press enter and you can read the email number 1:

So there is your test email. Press "q" to quit "mutt".
Access the email using IMAP
Actually we just cheated a little as we have accessed John's inbox directly on disk. A better test is to use POP3 or IMAP. And fortunately "mutt" supports IMAP:
mutt -f imap://john@example.org@localhost
You may be prompted to confirm that you are connecting to a mail server with an untrusted SSL certificate. That's okay. In the end you should see the index and email just like in the screenshots above. That worked? Great. Otherwise check your /var/log/mail.log for error messages.
If you still can't get enough and want to run a manual POP3 and IMAP session using TELNET then check out the Lenny tutorial on a complete example.
POP3 versus IMAP
If you wonder what the difference between POP3 and IMAP is:
- POP3 (Post Office Protocol) is a simple protocol that lets you fetch email from a single mailbox. It is usually used to collect all emails, though you can also leave them on the server but this is a bit of a hack and you can't create multiple folders on the server to sort your mail. It saves space on the mail server because the email gets moved to the user's hard disk on their computer. But they won't be able to access the same email from another computer. Besides you cannot create multiple folders on the server to sort your mail. There is just the inbox. This variant is antiquated and not exactly user-friendly.
- IMAP (Internet Messaging Application Protocol) is predominantly focused upon leaving your mail on the server but you can also collect it like POP3. The inbox is where your incoming emails are stored but users can also maintain folders and move emails to them. But users can move emails to different directories. IMAP is useful when you want to access your email from different locations without losing mail because you fetched it from another location. The drawback is that lazy users leave their mail on the server thus filling up your server's hard disk (unless you use quotas).
77 Comments
Strip 'Received' header from outbound e-mails in Postfix?
Submitted by Anonymous (not verified) on
I want to, on my Postfix setup, remove/drop/ignore/alter the earliest "Received" header if I'm an authenticated user with a relevant privilege in the MySQL database. But I want to only do this with outbound e-mails. Everywhere I've looked either has people telling others not to do this while simultaneously accusing the author of the request of being a spammer, set up some sort of VPN solution (not a reasonable option), or, very rarely, making real suggestions to use things like 'header_checks' that affect both directions (inbound and outbound).
Do you know of a solution that works? Seems like a problem that should be easily solved.
Had the same problem. I ran
Submitted by Anonymous (not verified) on
Had the same problem. I ran across this:
https://we.riseup.net/debian/anonymizing-postfix
That solution works great even for multiple hosts.
Domain name in user directory
Submitted by Anonymous (not verified) on
I have a issue when I send a test email to testuser@domainame.com.
It creates /var/vmail/domainame.com/testuser@domainame.com/Maildir/
instead of /var/vmail/domainame.com/testuser/Maildir
I checked my configuration but I din't find my mistake.
Any idea ?
Thanks.
What is "mail_location" set
Submitted by Christoph Haas on
What is "mail_location" set to in your /etc/dovecot/dovecot.conf?
Thanks, this was the error
Submitted by Anonymous (not verified) on
I was maildir:/var/vmail/%d/%u/Maildir
I changed it to maildir:/var/vmail/%d/%n/Maildir
and worked OK.
Thanks a lot!
My test fail
Submitted by Anonymous (not verified) on
In my case:
find: «/var/vmail»: No existe el fichero o el directorio
find: «/var/vmail»: No existe el fichero o el directorio
#cat /var/log/mail.log
Nov 12 10:22:46 Debian postfix/pickup[7507]: 9881B2610C2: uid=0 from=<root>
Nov 12 10:22:46 Debian postfix/cleanup[7552]: 9881B2610C2: message-id=<20111112145246.9881B2610C2@Debian.linktch.net>
Nov 12 10:22:46 Debian postfix/qmgr[7508]: 9881B2610C2: from=<root@mail.linktch.net>, size=292, nrcpt=1 (queue active)
Nov 12 10:22:46 Debian postfix/pipe[7555]: fatal: get_service_attr: unknown username: vmail
Nov 12 10:22:47 Debian postfix/qmgr[7508]: warning: private/dovecot socket: malformed response
Nov 12 10:22:47 Debian postfix/qmgr[7508]: warning: transport dovecot failure -- see a previous warning/fatal/panic logfile record for the problem description
Nov 12 10:22:47 Debian postfix/master[3196]: warning: process /usr/lib/postfix/pipe pid 7555 exit status 1
Nov 12 10:22:47 Debian postfix/master[3196]: warning: /usr/lib/postfix/pipe: bad command startup -- throttling
Nov 12 10:22:47 Debian postfix/error[7556]: 9881B2610C2: to=<john@example.org>, relay=none, delay=1.1, delays=0.08/1/0/0.05, dsn=4.3.0, status=deferred (unknown mail transport error)
I missing something? any help?
My mistake
Submitted by Anonymous (not verified) on
I make a mistake following the "Setting up Dovecot" page.
Sorry ;) now everything go fine, until now.
BTW excelent guide... thank you very much!
Not receiving mails
Submitted by Anonymous (not verified) on
Hello, i got a problem, i can send emails but not receive them.
The log:
auth(default): passwd(userx@domain.com,127.0.0.1): unknown user
Nov 22 16:17:32 servidor1 dovecot: imap-login: Login: user=<userx@domain.com>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, secured
Nov 22 16:17:32 servidor1 dovecot: IMAP(userx@domain.com): Disconnected: Logged out bytes=85/681
i'm using squirrelMail and i can login and as i said send emails, but can't receive even using accounts of the same domain.
Any Idea.
Solved, but, new error
Submitted by Anonymous (not verified) on
Ok i found out that squirrelMail doesn't show my mails, and the error was because of the user passwd option, it was uncommented, now it works.
But i got a new problem, i can't receive from external servers as hotmail i have godaddy host do i need any special configuration?
Thanks.
/var/vmail still epmty
Submitted by Anonymous (not verified) on
Fixed
Submitted by Anonymous (not verified) on
As long as it helps to get
Submitted by Christoph Haas on
As long as it helps to get your mail server running that's fine. :) I just don't like unsolicited advertising.
Anyway… your pastebin link is now remived.
Keine Berechtigung (errno = 13)
Submitted by Anonymous (not verified) on
Hello,
thanks a lot. Your workaround works fine :-)
The Testing is the Problem.
The command works but i get mails from root ? The user and the domain exists and the mails arrived my from the user. When i aswer to the mail i get it from root.
if i type without root in my user (my username == my mailname) and type mutt -f /var/vmail/domain/user/Maildir
I get the error
How can i set the systemusername as the Mailname?
imap vs imaps [solved] ^^
Submitted by Paul (not verified) on
firstly: thank you very much for this exquisite tutorial!
since i'm on the slightly paranoid edge of running a mailserver, i only allow imaps and pop3s. So i followed the tut and run into the following:
"Kann keine Verbindung zu localhost aufbauen (Verbindungsaufbau abgelehnt)."
In case some of you get an error like "Can't establish connection to localhost (Connection rejected)",
you have to add an extra 's' to the mutt-imap-parameter. If you disabled standard IMAP and only allowed IMAPS in 'protocols' section of dovecot.conf, the string has to look as follows:
mutt -f imaps://john@example.org@localhost
---------------î
thanks again for the tutorial!
authenticated SMTP
Submitted by Stefano (not verified) on
first of all many thanks to Cristoph who wrote this excellent guide and sorry for my english, i know it is very bad
Now on my problem : i followed this guide to setup my mail server and everything works fine but SMTP.
I can telnet localhost on port 25 and it asnwers
i can telnet localhost on port 587 ( it's enabled in master.cf obviously)
I can send mail to external domains via webmail
i cannot send via mail client, with authentication or not.
telnetting to port 25 mailserver answer but i cant send to any external domain
telnetting to port 587 mailserver refuse connection with a 554 5.7.1 <unknown[IPADDRESS]>: Client host rejected: Access denied
what's wrong? Iìm sure I made a wrong configuration but i don't know where to modify it....
any help will be appreciated....
Don't worry about your
Submitted by Christoph Haas on
Don't worry about your english. :)
I suggest you take a look at your mail.log. It will probably tell you why the relaying was denied. I assume that you checked that SMTP authentication was enabled, right?
allow_all_users=no
Submitted by Dušan (not verified) on
I followed your manual step by step, but after installation I noticed, that all email are delivered and created own folder,
also wenn I sent email to unknown email address.
echo test | mail cccjohn@example.org
created /var/vmail/example.org/cccjohn/
So I removed all packages and followed the manual again, the same result.
I tried to change "allow_all_users=yes" to "allow_all_users=no" and it helped.
I just wanted to report it, maybe I made mistake.
By the way, these are excellent manuals for virtual emails, I have used them since Debian Sarge, thanks!
cannot add the homedir in /home/vmail/
Submitted by samtai (not verified) on
I am using debian testing to build my postfix server.
I follow this tutorial to configure my mail server, but when I try to send test mail using command "echo test | mail test@virtualmail.tld", the maildir didn't create in /home/vmail/ , I have already change the permission 644 to user and group for vmail account.
The following is the /var/log/mail.log:
Oct 29 17:03:57 localhost postfix/pickup[3398]: E989A62808: uid=0 from=<root>
Oct 29 17:03:57 localhost postfix/cleanup[3434]: E989A62808: message-id=<20121029090357.E989A62808@mail2.hometest.net>
Oct 29 17:03:57 localhost postfix/qmgr[3399]: E989A62808: from=<root@mail2.hometest.net>, size=290, nrcpt=1 (queue active)
Oct 29 17:03:57 localhost postfix/local[3438]: E989A62808: to=<fyp@mail2.hometest.net>, orig_to=<test@virtualmail.tld>, relay=local, delay=0.04, delays=0.03/0/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Oct 29 17:03:57 localhost postfix/qmgr[3399]: E989A62808: removed
Here is my /etc/postfix/main.cf:
myhostname = mail2.hometest.net
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = mail2.hometest.net, localhost
relayhost =
home_mailbox = Maildir/
mynetworks = 127.0.0.0/8 192.168.0.0/24
#mynetworks_style = host
mailbox_command =
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
# virtual domain and users setting
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_mailbox_domains.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
myorigin = /etc/mailname
inet_protocols = ipv4
I have the the mysql database, test@virtualmail.tld is in the virtual_users table and virtualmail.tld is in the virtual_domains table, and check them using the 'postmap -q' command both no error.
anyone know how to fix my problem?
The email got delivered using
Submitted by Christoph Haas on
The email got delivered using the "local" delivery daemon. You are sending an email to fyp@mail2.hometest.net and define mail2.hometest.net as a local domain. If you are not sure about local domains versus virtual domains I suggest you read this chapter again.
problem solved
Submitted by samtai (not verified) on
Thank you very much for your reply.
I was misunderstood about the "local domains versus virtual domains".
I found my mistake in the virtual_aliases table of mysql database,
my original like this:
+----+-----------+------------------+--------------------------------+
| id | domain_id | source | destination |
+----+-----------+------------------+--------------------------------+
| 1 | 1 | @virtualmail.tld | fyp@mail2.hometest.net |
+----+-----------+------------------+--------------------------------+
then I try to delete this row, every work well now. the email can receive in the /home/vmail/virtualmail.tld/fyp/Maildir/new
I have another question now,
if I want both email "fyp@virtualmail.tld" and "fyp@mail2.hometest.net" receive the same mail,
I must need to add two row in the databse table which are
source: fyp@mail2.hometest.net destination: fyp@virtualmail.tld and
source: fyp@mail2.hometest.net destination: fyp@mail2.hometest.net
Is that correct?
MTA issue
Submitted by Dietbrand (not verified) on
On a Linux VPS with Debian 6, you may get Sendmail as default MTA.
If you then perform echo test | mail your@email.com (where your@email.com is configured locally) you'll see the following error appear:
postdrop: warning: unable to look up public/pickup: No such file or directory
You need to stop the sendmail service and then start Postfix:
/etc/init.d/sendmail stop
/etc/init.d/postfix start
You'll know if Postfix is started when you do "ps aux | grep postfix" and get output like this
root 9790 0.0 0.1 37172 2400 ? Ss 17:30 0:00 /usr/lib/postfix/master
postfix 9795 0.0 0.1 39236 2376 ? S 17:30 0:00 pickup -l -t fifo -u -c
postfix 9796 0.0 0.1 39396 2496 ? S 17:30 0:00 qmgr -l -t fifo -u
Regards
Dietbrand
I'm surprised. Debian doesn't
Submitted by Christoph Haas on
I'm surprised. Debian doesn't allow two MTAs to be installed at the same time. So if you'd install Sendmail then Postfix would get removed. In addition by default Exim is installed as an MTA. Something seems to be pretty broken on the system you are dealing with.
I'm not sure
Submitted by Dietbrand (not verified) on
...why sendmail was still active. On another server I deinstalled Postfix after tragically failing to get Postfix and Dovecot to work. The last message I then got from the installer was that it was reactivating Sendmail again.
imap-login wrong user?
Submitted by samsn (not verified) on
Excellent guide thank you.
I have an issue.
When i try to send the test message "echo test | mail me@mydomain.tld" i get permission denied missing +w perm /var/vmail. for when it tries to create the maildirs in mail.log.
Where do i change what user dovecot imap-login uses to log in?
The user it is trying to login with is the basic user which i created when installing debian.
trivial-rewirte: MySQL socket
Submitted by Anonymous (not verified) on
trivial-rewirte: MySQL socket not available
My first test did not work as expected, I found this in /var/log/mail.log:
postfix/trivial-rewrite[xxx]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
postfix/trivial-rewrite[xxx]: fatal: mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf(0,lock|fold_fix): table lookup problem
The files /etc/postfix/mysql*.cf do not contain localhost, all hosts are set to 127.0.0.1. The iptables don't block anything, I also tested without any iptable-rules (all chains set to accept). It seems that trivial-rewrite is always connecting to MySQL via socket. But as long as it is running in chroot, /var/run/mysqld/mysqld.sock is not reachable.
I solved it now by taking it out from chroot by changing this line in /etc/postfix/master.cf:
rewrite unix - - - - - trivial-rewrite
to
rewrite unix - - n - - trivial-rewrite
I am not sure if it is secure to take rewrite out of chroot. Another hack would be to "mount" the mysql-socket inside the chroot, but that's not very nice. Any idea why this happens? Any better solution than the one I found? If I could tell rewrite to use 127.0.0.1 instead of the socket, this could be a solution. But I don't know how to do this.
trivial-rewrite: solved!
Submitted by Anonymous (not verified) on
After searching through nearly half of the internet I found the solution: It has to be "proxy:mysql:" instead of just "mysql:" in /etc/postfix/main.cf
With this configuration Posftix uses the MySQL TCP conenction instead of the socket (which is not available in chroot):
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-....cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-....cf
virtual_alias_map = proxy:mysql:/etc/postfix/mysql-...cf
Btw: Thank you Christoph, this tutorial is really great!
Testing secure protocols
Submitted by Alwyn (not verified) on
When testing using mutt -f imap://john@example.org@localhost I kept getting "telnet: Unable to connect to remote host: Connection refused"
The fix would be to change imap (or pop3) to imaps (or pop3s).
Another thing when testing is that the account (john@example.org) asks for a password. An empty password results in a authentication failure.
Pages