I'm looking to integrate a webmail system into a website I'm building. I'd basically like a webmail interface built into my existing application.

I need mail to be sent to their usernames and be read in the website. But, I'd also like users to be able to access their mail through IMAP as well. I need the user to authenticate with the mail server with their site credentials.

I know PHP can read IMAP boxes, but I'm under the impression that that's not very efficient for a large-scale multi-user environment. I know some mail daemons can store their boxes and messages in MySQL and authenticate against other systems. I'd imagine that'd be a smoother solution, no?

Any ideas on what systems to look into?

  • 1
    Why don't you try to customize SquirrelMail insted of reinventing the wheel?
    – lrosa
    Dec 6, 2010 at 17:15
  • Use an IMAP server that is smart enough to maintain its index, and does caching (ie Dovecot + maildir) and the concern about IMAP efficience becomes a lot less relevant.
    – Zoredache
    Dec 8, 2010 at 0:12
  • Try github.com/MonstaApps/PHP-IMAP-Fetcher. Pipe or fetch emails, log to MySQL, and save attachments. Dec 20, 2017 at 1:09

3 Answers 3


Most mail daemons can authenticate against other backends (MySQL, Postgres, LDAP are most common). If you are using some kind database of for site, just put correct queries in postfix config to authenticate against your site database.
Storing e-mails in database is unefficient because of additional overhead introduced. For most cases, maildir is the way to go.
IMAP handles a lot of things, including mail client concurrency, folders, deletion, authentication - reinventing most of them feels "not right".
I had run webmail for 10 000 clients using roundcube and single box with IMAP (caching imap connection using imapproxy to avoid auth overhead on each request).

  • So, when I want to display mail on the web app, I'd use the PHP IMAP library to read the data, with imapproxy for caching? Dec 6, 2010 at 18:09

Why reinvent the wheel like Irosa said? Look into Google Apps: http://www.google.com/apps/intl/en/business/index.html

You can host all of your email there and never have to worry about server configurations, mail delivery, ports, security, etc. You can use any domain name and can customize the logo/coloring of the page.


Please refer the URL http://php.net/manual/en/book.imap.php with help of which you can integrate your Mail (IMAP) with PHP.

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.