我想连接电子邮件和应用程序的接收

时间:2020-12-31 07:10:28

If an email sent on XXXX@YYYY.ZZZ, I want to put the contents of the email in a database, but how may realize it? I use postfix to MTA.

如果在XXXX@YYYY.ZZZ上发送电子邮件,我想将电子邮件的内容放在数据库中,但是如何实现呢?我使用postfix到MTA。

2 个解决方案

#1


If you definitely must, write a program to process the input (say /usr/bin/your_program) and place this in /etc/aliases:

如果你肯定必须,编写一个程序来处理输入(比如/ usr / bin / your_program)并将其放在/ etc / aliases中:

intended-local-address: "|/usr/bin/your_program"

#2


I have used fetchmail. If You configure it right, it can make a blocking call to a remote IMAP server (it will hang until a mail is received, how cool is that, no active polling!). It handles many kinds of mail protocols. It puts the email with it's headers into a program of Your choice (I used python and it's builtin mail parsing libary).

我用过fetchmail。如果您正确配置它,它可以对远程IMAP服务器进行阻止调用(它将挂起,直到收到邮件,这有多酷,没有活动轮询!)。它处理多种邮件协议。它将带有它的标题的电子邮件放入您选择的程序中(我使用了python,它是内置邮件解析库)。

I must say I am proud of this solution, as it was relatively easy to setup and very effective on the end.

我必须说我为这个解决方案感到自豪,因为它相对容易设置并且最终非常有效。

Few more things worth noting:

更多值得注意的事情:

  1. The connection times out or resets eventually (after several hours, sometimes several weeks). I suspect that the IMAP server was being restarted.
  2. 连接超时或最终重置(几小时后,有时几周)。我怀疑IMAP服务器正在重启。

  3. Don't try to parse the email by Yourself. I gave up after debugging the 5th way of sending email body and then used the existing lib.
  4. 不要试图自己解析电子邮件。我调试了第5种发送邮件正文的方式然后使用现有的lib后放弃了。

  5. After the poll finishes, do a sleep 5 or something before You poll again. My mail program once felt into an infinite loop with another one and the sleep 5 saved me.
  6. 轮询完成后,在再次轮询之前,请先进行5次睡眠。我的邮件程序曾经感觉到与另一个邮件程序无限循环,睡眠5节省了我。

#1


If you definitely must, write a program to process the input (say /usr/bin/your_program) and place this in /etc/aliases:

如果你肯定必须,编写一个程序来处理输入(比如/ usr / bin / your_program)并将其放在/ etc / aliases中:

intended-local-address: "|/usr/bin/your_program"

#2


I have used fetchmail. If You configure it right, it can make a blocking call to a remote IMAP server (it will hang until a mail is received, how cool is that, no active polling!). It handles many kinds of mail protocols. It puts the email with it's headers into a program of Your choice (I used python and it's builtin mail parsing libary).

我用过fetchmail。如果您正确配置它,它可以对远程IMAP服务器进行阻止调用(它将挂起,直到收到邮件,这有多酷,没有活动轮询!)。它处理多种邮件协议。它将带有它的标题的电子邮件放入您选择的程序中(我使用了python,它是内置邮件解析库)。

I must say I am proud of this solution, as it was relatively easy to setup and very effective on the end.

我必须说我为这个解决方案感到自豪,因为它相对容易设置并且最终非常有效。

Few more things worth noting:

更多值得注意的事情:

  1. The connection times out or resets eventually (after several hours, sometimes several weeks). I suspect that the IMAP server was being restarted.
  2. 连接超时或最终重置(几小时后,有时几周)。我怀疑IMAP服务器正在重启。

  3. Don't try to parse the email by Yourself. I gave up after debugging the 5th way of sending email body and then used the existing lib.
  4. 不要试图自己解析电子邮件。我调试了第5种发送邮件正文的方式然后使用现有的lib后放弃了。

  5. After the poll finishes, do a sleep 5 or something before You poll again. My mail program once felt into an infinite loop with another one and the sleep 5 saved me.
  6. 轮询完成后,在再次轮询之前,请先进行5次睡眠。我的邮件程序曾经感觉到与另一个邮件程序无限循环,睡眠5节省了我。