-->

How to communicate with a mail server through a we

2020-02-12 07:23发布

问题:

I am really unfamiliar with mail servers in general so please excuse my ignorance.

I need to be able to administer a mail server through my Spring-based web application. By administer, I mean creating mail accounts for new users, listening for incoming updates from those users, deleting accounts, when user accounts are deleted, etc, etc, etc.

I assume that mail servers (at least the good ones) provide some sort of a service API (SOAP, REST, it doesn't matter) through which an application can hook, and make changes. However, i am really unfamiliar with regards to what the good open-source servers out there are, and what options they provide.

I will be glad if someone, could propose a solution.

回答1:

There is a mail server called Zimbra which has an open source community edition, which has a REST interface and also a SOAP one.

  • REST reference (if I understand correctly this won't suit your needs because you can only manipulate existing account via this)
  • SOAP interface; one example here, there are many others on the forum.


回答2:

A possible solution is to use software with a generic database plugin. Your web application does not interact with the mail server, instead it just fills a users table in a mysql database. in the simplest case this table has a username field and a password field. In most real-life setups a few additional fields are required like "user is disabled" or "user can connect with IMAP", "location of users homedir/maildir", ... If your users can create new domains as well, you also need a table for that.

Then, you need mail server software with a database backend.

For hosting the mailboxes, you could use the dovecot IMAP/POP3 server. It supports all the fancy stuff like user quota, auto-creation of mailboxes etc. Here, you'll find documentation on how to configure dovecot with a database backend: http://wiki2.dovecot.org/AuthDatabase/SQL

For actually receiving the mail by stmp you also need a MTA software. Here, a good choice would be postfix. If your users can create new domains, you need to add mysql configuration that tells postfix which domains it may accept mail for. Since I don't know your domain requirements exactly I'm just going to point you to the general postfix virtual domain hosting howto: http://www.postfix.org/VIRTUAL_README.html

Finally, if your users should be able to send mail as well you need to configure SASL in postfix. This is quite simple if you already have dovecot configured. it boils down to telling postfix "hey, I already have user authentication configured in dovecot, I don't want to do it again, just talk to dovecot and let it do the job". Documentation is here: http://www.postfix.org/SASL_README.html#server_dovecot