有哪些方式可以对具有.NET code运行和处理邮件到达时?以对、邮件、方式、有哪些

2023-09-02 02:03:24 作者:云中寄锦书

我一直致力于创建某种服务的,将采取任何电子邮件发送至E-mail地址和处理电子邮件的内容(包括二进制附件。)

I've been tasked with creating some sort of service that will take any e-mail sent to an e-mail address and handle the contents of the e-mail (including binary attachments.)

我已经得到了完全访问服务器(Windows Server 2008),将运行此服务,并已决定code使用.NET Framework(3.5)的解决方案。

I've got full access to the server (Windows Server 2008) that will run this service, and have decided to code the solution using the .NET framework (3.5).

现在我正在考虑不同的方法,我可以做到这一点。由于我不是很有经验在处理电子邮件编程,即进入了我的脑海中第一个解决方案是创建一个电子邮件客户端,将定期轮询现有的邮件服务器来发送电子邮件(使用POP3协议)并对其进行处理。但也有其他方法可以做到这一点。

Now I'm thinking about the different ways I can do this. Since I'm not very experienced in handling e-mails programmatically, the first solution that came into my head was to create an e-mail client that will periodically poll an existing e-mail server for incoming e-mail (using the POP3 protocol) and process them. But there are other ways to do it.

一个可以使用IMAP来保持连接到邮件服务器,并尽快为他们到达取电子邮件(反应更灵敏,但我相信IMAP协议是很难实现的。)这里的后续问题是:我在哪里可以找到支持POP3或IMAP协议可靠的电子邮件库?

One could be to use IMAP to stay connected to the mail server and fetch e-mails as soon as they arrive (more responsive, but I believe the IMAP protocol is harder to implement.) The follow-up question here is: where can I find reliable e-mail libraries that support the POP3 or the IMAP protocol?

另一个可能以某种方式配置邮件服务器以直接管道发送到特定地址到我的二进制code中的电子邮件(我已经看到这种情况在Linux服务器上。)我不知道怎么样去了解这一点,虽然。

Another could be to somehow configure the e-mail server to directly pipe the e-mails sent to a specific address to my binary code (I've seen this done on Linux servers.) I have no idea how to go about this, though.

最后我能想到的是创建一个虚拟邮件服务器上自己的地址直接处理电子邮件,因为它到达,但对我来说这似乎是一个坏主意。

The last I can think of would be to create a dummy e-mail server on its own address that handles the e-mail directly as it arrives, but to me this seems like a bad idea.

有没有人有这方面的经验?我猜想,不必写邮件处理程序票支持系统是不是少见,所有我需要另外就是处理附件。

Does anyone have experience in this area? I would imagine that having to write e-mail handlers for ticket support systems isn't that uncommon, all I need in addition to that is to handle the attachments.

我会很感激任何提示和技巧。

I'd be grateful for any hints and tips.

推荐答案

正如很多东西 - 它依赖。问问自己以下几个问题:

As with alot of things - it depends. Ask yourself the following questions:

什么是您的等待时间要求 - 你需要尽快处理传入的消息有可能,或可处理进行批处理?如果可以分批,然后多久会你必须处理收件箱?

What are your latency requirements--do you need to process incoming messages as quickly as possible, or can processing be batched? If it can be batched, then how often would you have to process the "inbox"?

什么是您的吞吐量需求?我们有多少邮件谈论每分钟吗?有多大的消息?这会影响到你,如果使用批处理的情况做出轮询间隔的决定;

What are your throughput requirements? How many messages are we talking about per minute here? How big are the messages? This would affect the decision you make about polling interval if using a batch scenario;

您整合与什么样的邮件系统?如果它是交易所,是什么编程接口可用来访问邮箱?直到最新版本的Exchange,有趣的是,有问题的Exchange服务器上访问邮箱(所需的客户端CDO COM组件中使用是不理想---并有安全限制)。

What sort of e-mail system are you integrating with? If it's Exchange, what programmatic interfaces are available to access a mailbox? Until the most recent version of Exchange, interestingly enough, there were issues with accessing a mailbox on an Exchange server (The client-side CDO COM components needed to be used which is not ideal---and there were security limitations).

目前为止最简单的方法是查询使用POP3邮箱。但是,如果你需要应对的马上的进来的消息,那么这是不会削减它。

By far the simplest approach is to poll a mailbox using POP3. However, if you need to respond immediately to an incoming message, then this isn't going to cut it.

尽可能的避免的编写自己的SMTP服务 - 它已经做过上千次,你只是在为自己创造不必要的工作,揭露自己的安全威胁。如果你的绝对有的到的消息立即做出反应,然后而设置的Sendmail 或后缀产卵,你已经写了一个过程。

As far as possible avoid writing your own SMTP service--it's been done a thousand times before and you're just creating unnecessary work for yourself and exposing yourself to security threats. If you absolutely have to respond immediately to messages, then rather set up an instance of Sendmail or Postfix to spawn a process that you have written.

如果你打算去为POP3溶液(它看起来像你),然后让相关问题读的免费POP3 .NET库?和阅读电子邮件使用POP3在C#中。

If you're going to go for the POP3 solution (it looks like you are), then have a read of related questions "Free POP3 .NET library?" and "Reading Email using POP3 in C#".