I needed to let PHP send mails from my webserver to my web app users. So I installed qmail on my Debian server:

sudo apt-get install qmail

I also updated files in /etc/qmail specifing my domain name, and then I run sudo qmailctl reload and sudo qmailctl restart:

/etc/qmail/defaultdomain # Contains 'mydomain.com'
/etc/qmail/defaulthost   # Contains 'mydomain.com'
/etc/qmail/me            # Contains 'mail.mydomain.com'
/etc/qmail/rcpthosts     # Contains 'mydomain.com'
/etc/qmail/locals        # Contains 'mydomain.com'

Emails are sent without any problem from my PHP script to any email address, using the standard mail PHP library.

Now the problem is that if I send mail from my PHP using info@mydomain.com as sender address, I want that customer can reply to that address! And possibly, I want all mails sent to this address should be forwarded to my personal Gmail address.

At the moment qmail seems to not accept any incoming mail because of "invalid mailbox name". Here is a complete SMTP session I established with my server:

me@MYPC:~$ nc mydomain.com 25

220 ip-XX-XX-XXX-XXX.xxx.xxx.xxx ESMTP
HELO me@MYPC.org
250 ip-XX-XX-XXX-XXX.xxx.xxx.xxx
250 ok
RCPT TO:<info@mydomain.com>
250 ok
554 sorry, invalid mailbox name(s). (#5.1.1)

I'm sure I missing something related to mailbox or alias creation, in fact I did nothing to define mailbox info@mydomain.com anywhere. But I tried to search something on the net and on the numerous qmail man pages, bot I found nothing.

  • Is there a reason why you don't have PHP send directly to Gmail and leave qmail out of it? – John Gardeniers Sep 13 '12 at 12:37
  • @JohnGardeniers Yes. Read my question well. I want my email to be sent by server itself using an address that contains my web app domain. And I want my customer to write theirs to that same email address (that contains my web app domain, again). – lorenzo-s Sep 13 '12 at 13:27

There are two basic ways for qmail to figure out how to handle the localpart of the email address. The first is to check whether there's an actual account for that name - so if you had a user called info on your server, that user would get the mail. The second way is to look for an alias file. That's a file that's called .qmail-localpart and when the server only handles one domain, that file should be in /var/qmail/alias (or /etc/qmail/alias or /var/lib/qmail/alias).

So, what you need to do is:

  • create a file called /etc/qmail/aliases/.qmail-info (or maybe /var/qmail/aliases/.qmail-info, depending on your setup)
  • that file should contain the text &your.address@gmail.com

That should be all! For more information on qmail, I recommend Dave Sill's Life with qmail. There's also a qmail mailinglist, though I'm not sure how active it is - it's been a few years since I was an email sysadmin so I've left the list.

  • Cool. I tested a manual SMTP connection sending an email to lorenzo@mydomain.com (where lorenzo is my actual user on that server) and email has been accepted (in the log: delivery 2: success: did_0+0+1/). I have no idea where that email has been stored, btw! Now I try to set up an alias. – lorenzo-s Sep 13 '12 at 9:28
  • Great! It works. I edited your answer because I found aliases definition in another place. My only question now is... When not forwarded, where messages to actualuser@mydomain.com are stored? – lorenzo-s Sep 13 '12 at 9:51
  • I found them in /var/mail. Cool. Thank you very much @JennyD ! – lorenzo-s Sep 13 '12 at 10:23
  • Glad it worked! I feel almost sentimental answering questions about the mail system I used to work with some years ago :-) – Jenny D Sep 13 '12 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.