简体   繁体   English

发送/接收/解释动态电子邮件

[英]Sending/Receiving/Interpreting Dynamic Email

I wanted to write a program that can receives an email, interprets what the message is, then performs a calculation, then responds based on the email received. 我想编写一个程序,该程序可以接收电子邮件,解释消息内容,然后进行计算,然后根据收到的电子邮件进行响应。

For example: 例如:

The mail server receives an email that has "option 1" in the body...then somehow the mail server asks the program what it should do in the event of option 1. The program performs some calculations, then asks a SQL server to relay some data related to option 1. The mail server then returns a dynamically created message "option 1 means xxx". 邮件服务器接收到一封电子邮件,该邮件的主体中包含“选项1” ...然后,邮件服务器以某种方式询问程序在选项1的情况下应该做什么。程序执行一些计算,然后要求SQL Server进行中继一些与选项1相关的数据。邮件服务器然后返回动态创建的消息“选项1表示xxx”。

I really have no idea where to start on this one. 我真的不知道从哪里开始。 A friend recommended PostFix but I'm not exactly sure where any program logic can be performed. 一位朋友推荐了PostFix,但我不确定在哪里可以执行任何程序逻辑。 Any ideas or suggestions are welcome. 欢迎任何想法或建议。

The procmail mail processor is very good at this. procmail邮件处理器非常擅长于此。 Examples should be in the documentation. 示例应在文档中。 It essentially allows you strip mail bodies from headers given conditions (eg 'security' tokens, 'passwords', 'addresses', ...) and to then pipe the mail body through other arbitrary programs. 从本质上讲,它允许您从给定条件(例如“安全”令牌,“密码”,“地址”等)的标头中剥离邮件正文,然后通过其他任意程序通过管道传递邮件正文。

You can do this using a regular POP3/IMAP and SMTP setup. 您可以使用常规的POP3 / IMAP和SMTP设置来执行此操作。

  1. Monitor the Mailbox for incoming messages 监视邮箱中的传入邮件
  2. Download the message and parse the contents 下载消息并解析内容
  3. Process your events as needed 根据需要处理事件
  4. Generate a SMTP response to the sender and respond. 生成对发件人的SMTP响应并进行响应。

Some helpful links: 一些有用的链接:

  1. System.Net.Mail System.Net.Mail
  2. Processing POP3 messages in C# 在C#中处理POP3消息

PS We have done this at several jobs I have worked at, its actually very straight forward. PS:我在做过的几项工作中都做到了这一点,这实际上非常简单。

Chris, I started here: codeproject - NetPopMimeClient . 克里斯,我从这里开始: codeproject-NetPopMimeClient Using this I wrote a program to check for a new inventory email based on subject text (inventory attached.) When I found a new one I would save the attachment and then upload it to my sql server and kick off a stored proc to process it. 使用此程序,我编写了一个程序,用于根据主题文本(附件中的清单)检查新的清单电子邮件。找到新附件时,我将保存附件,然后将其上传到sql服务器,并启动存储的proc处理该附件。 。 Then saved the email DateTime stamp for the next run and to display to the user on the front-end. 然后保存电子邮件DateTime戳以进行下一次运行,并在前端显示给用户。

I created a Console Application that is scheduled in SQL Server Agent. 我创建了在SQL Server代理中安排的控制台应用程序。 I did this so I can have a log of activity, it is close to the database, it is easy to kick off manually, and it emails out when there is a problem. 我这样做是为了获得活动日志,它靠近数据库,很容易手动启动,并且在出现问题时通过电子邮件发送出去。

Jim 吉姆

If your mailserver can be connected via IMAP4, I recommend taking a look at IMAPFilter . 如果您的邮件服务器可以通过IMAP4连接,则建议您查看IMAPFilter You can implement a LUA script to take certain actions based on the content of the emails. 您可以实施LUA脚本,以根据电子邮件的内容采取某些措施。 I found a blog post that might give you some hints on how to get started. 我找到了一篇博客文章 ,该文章可能会给您一些入门提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM