N
N
nani2013-08-03 13:29:53
PHP
nani, 2013-08-03 13:29:53

Reception of mail by application backend (PHP)

It is necessary that the incoming mail be transferred to PHP (along with the attachment) to perform some action, for example, to publish a comment on a blog post.

The main condition is that messages should not be lost. That is, if the server with PHP is down, the message must be processed by it later.
A feature of the task is that a lot of mailing addresses from which you need to receive mail can be created. These email addresses will also work for sending mail.

So far, I see several implementation options:
1. Call a PHP script when receiving mail and send messages there. In this case, it is not clear how to ensure the reliability of delivery - messages can be lost.
2. Find a way for the mail server to interact with the AMQP server, send messages there. In this case, the mail server should probably be able to respond to the letter with an error if AMQP suddenly lies.
3. Call a PHP script using the cron, which will connect to mailboxes, check for new mail and perform operations with it. Will there be a problem here that there can be a lot of postal addresses? In addition, the scalability of such a solution is questionable.

Have you faced such a task and what implementation option would you suggest? Are there recommendations for specific technologies and libraries (postfix, etc.)?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
merlin-vrn, 2013-08-03
@nani

Solution 1 in the case of Postfix is ​​simple and elementary. Why are you so afraid for the reliability of delivery in this case? The queue will make Postfix for you, and it will feed the script letters one at a time to stdin: it gave one letter, the script ended - it starts the next process and gives the next one to it. For one of our clients, such a scheme has been working for several years, only on acceptance the script is not in PHP but in Python (once it was on TCL, but it was inconvenient to support this if the TCL MIME library was buggy). All messages are redirected there using always_bcc, i.e. the script actually processes all mail in general, about a hundred addresses.
Solution 2 - you add an extra layer between the mail server and the script, the task of which is actually solved by the queue manager of the mail server itself.
Solution 3 - works in many places, but with a large number of boxes it is inconvenient. It is possible to wrap everyone in one and check it, but again, an additional layer appears between the script and the mail server. On the other hand, it is universal, you can make friends with any server with any script. This approach, for example, is used internally by OTRS.

E
edogs, 2013-08-03
@edogs

Solved such a problem.
Based on the set of parameters and taking into account the limited budget, they did so.
From all addresses there is a forward / copy to one address, from where they are taken by a PHP script using the crown.
Dumb, simple, reliable, scalable...cheap. It could have been better, but it would have been more expensive :)

L
la0, 2013-08-03
@la0

The hardest part is parsing. I have already thoroughly fucked up with this and here is an alternative: habrahabr.ru/qa/43786/

S
Stanislav Sviridenko, 2013-08-05
@Terol

Look at www.mandrill.com/ There is an interception of all mail in their north and then a calm analysis on your part of letters in the form of JSON

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question