Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate with a mail server through a web application

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.

like image 914
user802232 Avatar asked Jun 21 '11 09:06

user802232


People also ask

How do I connect to my email server?

Navigate to the Email section. In the Hostname field, enter the name of the host. In the Port field, enter the number of the port. Optional: If your email server requires you to authenticate, in the Username field, enter a user name to use for authorization with the SMTP server.

How do mail servers communicate with each other?

Mail Transfer Agents (MTAs) communicate with each other over the internet using SMTP protocol (SMTP servers). The recipient's MTA then forwards the email to the incoming mail server (MDA, mail delivery agent), tasked with storing the mail until the user accepts it.

What is a mail server application?

A mail server -- also known as a mail transfer agent, or MTA; mail transport agent; mail router; or internet mailer -- is an application that receives incoming email from local users and remote senders and forwards outgoing messages for delivery.

Is SMTP needed for a Web server?

A SMTP server is always required to be able to send emails, like as a HTTP server is always required to be able to send webpages. This is regardless of the website and the mail API you're using. A HTTP server is not the same as and does usually not include a SMTP server.


1 Answers

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

like image 59
Gryphius Avatar answered Nov 15 '22 06:11

Gryphius