处理传入的电子邮件

发布于 2024-07-11 18:15:26 字数 408 浏览 5 评论 0原文

如何使用 .NET 以编程方式读取传入的电子邮件。 我需要一种方法来获取 POP 服务器上的电子邮件内容(在本例中为 XML)并将其读入我的应用程序。

理想情况下,这可以通过以下方式解决:

  • .NET 代码,我可以将其作为 我的网络服务器上的后台任务 处理电子邮件。
  • 可以发布内容的服务 发送到我的网络服务器的电子邮件。

尽管我对其他选择持开放态度。

编辑:从“非答案”复制:

目前,我们正在考虑使用 我们的托管公司的电子邮件帐户 提供。

我们自己的邮件服务器可能会 是一种选择,但它是 我们需要联系房东。

How do I programmatically read an incoming email with .NET. I need a method to take the content of email message (in this case XML) on a POP server and read it into my application.

Ideally this could be solved by:

  • .NET code that I can run as a
    background task on my webserver to
    process the email.
  • A service that can POST the contents
    of the email to my webserver.

Although I'm open to other options.

EDIT: Copied from the "non-answer":

Currently, we're looking at using the
email accounts our hosting company
provides.

Our own mail server could potentially
be an option, but its something the
we'd need to contact the host about.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

じ违心 2024-07-18 18:15:26

我们实际上刚刚实现了同样的事情。

我们处理电子邮件内容并通过网络服务将数据推送到我们的 CRM。 我们使用 c# 和 .net 3.5

来处理我们使用 IMap 的邮件。 CodeProject 上有一些 .net 客户端库。 我想我们使用了 LumiSoft 中的那个。

我们尝试过 WebDav 但运气不佳。 这给我们留下了 Pop3 或 IMap。 IMap 支持我们需要的文件夹,所以我们就这么做了。 我确信如果您的服务器不支持 IMap,那么使用 POP3 可以很容易地执行相同的操作。

基本上,我们每小时连接一次 Exchange 服务器并提取所有新电子邮件并进行处理。
到目前为止,它运作良好。

编辑:我们还使用 SharpMimeTools 将原始电子邮件转换为更可用的格式。

We have actually just implemented the same kind of thing.

We process the content of email messages and push the data in to our CRM via a web service. We use c# with .net 3.5

To process the mail we went with IMap . There are a few .net client libraries on CodeProject. I think we used the one from LumiSoft .

We tried WebDav but didn't have much luck. This left us with Pop3 or IMap. IMap supports folders, which we needed, so we went with that. I'm sure it would be easy to do the same thing with POP3 if your server does not support IMap.

Basically we connect our Exchange server every hour and pull down any new email and process them.
So far it's working well.

Edit: We also use SharpMimeTools to get the raw emails in to a more usable format.

っ左 2024-07-18 18:15:26

有很多选项,如果您有服务总线可供使用,它大多带有 pop3 适配器。

或者您可以使用 pop3 api(来自 quiksoft 的 easymail 是一个非常好的)。
它还有一个用于处理退回邮件的出色产品。

读取所有 SMTP 消息。 如果您拥有邮件服务器,根据服务器的类型,还有其他方式来获取消息,有时是自定义 API 和插件,或文件系统。 您拥有自己的邮件服务器吗?
您使用哪个邮件服务器?

如果可能的话,我不会选择 POP 协议,它有一些限制,例如只有一个文件夹、“获取/读取”消息会从文件夹中删除消息(这意味着需要一个进程来读取消息)等。 根据您需要解析的邮件数量,它可能仍然适合您。 IMAP 已经是一个改进。

使用 quiksoft IMAP 组件:

//create a new IMAP4 object, connect 
//to a IMAP4 server and login 
IMAP4 imap = new IMAP4();
imap.Connect("mail.yourdomain.com");
imap.Login("mailbox", "password");

//select the inbox and download the envelopes
imap.SelectMailbox("Inbox");
EnvelopeCollection imapEnvelopes;
imapEnvelopes = imap.GetEnvelopes();

//loop through each message
//and output the subject
foreach (Envelope imapEnvelope in imapEnvelopes)
{
   //write the subject out to the console
   Console.WriteLine(imapEnvelope.Subject);
}

//close resources
imap.Logout();

There are quite a few options, in case you have a service bus to your disposal it mostly comes with a pop3 adapter.

Or you can use a pop3 api (easymail from quiksoft is quite a good one).
It also has a great product for processing bounces.

To read all the SMTP messages. If you own the mailserver, depending on the type of server there other ways to get to the messages, sometimes custom Apis and plugins, or the filesystem. Do you host your own mail server?
Which mailserver do you use?

If possible I would not choose for the POP protocol, it has some limitations amongst other things like only having one folder, "getting/reading" a message removes the message from the folder (which means one process to read the messages) and other things. Depending on how many mails you need to parse it might still work for you. IMAP would already be an improvement.

With the quiksoft IMAP component:

//create a new IMAP4 object, connect 
//to a IMAP4 server and login 
IMAP4 imap = new IMAP4();
imap.Connect("mail.yourdomain.com");
imap.Login("mailbox", "password");

//select the inbox and download the envelopes
imap.SelectMailbox("Inbox");
EnvelopeCollection imapEnvelopes;
imapEnvelopes = imap.GetEnvelopes();

//loop through each message
//and output the subject
foreach (Envelope imapEnvelope in imapEnvelopes)
{
   //write the subject out to the console
   Console.WriteLine(imapEnvelope.Subject);
}

//close resources
imap.Logout();
单身情人 2024-07-18 18:15:26

爱思华宝的 Merak 电子邮件服务器非常适合这一点。 它让我们可以设置一种特殊的帐户,称为可执行帐户。 您将 .exe 与电子邮件地址相关联,并选择一堆要在命令行上发送的内容。 当电子邮件发送到该帐户时,它会触发可执行文件。 .exe 必须是一个控制台应用程序,您必须注意它不会挂起等等,但我认为这是完美的解决方案。

我们用它来处理来自谷歌分析的处理统计数据和来自其他邮件服务器的反弹。

IceWarp's Merak email server was great for this. It let us setup an special kind of account called an executable account. You associate a .exe with the email address and pick a bunch of things to send on the command line. When an email get sent to that account, it fires off the executable. The .exe has to be a console app and you must take care that it doesn't hang and what not, but I thought it was the perfect solution.

We use it to handle processing stats from google analytics and bounce backs from other mail servers.

寂寞美少年 2024-07-18 18:15:26

你总是可以 DIY POP 3 类
POP 是最简单的协议之一

You could always DIY A POP 3 Class
POP is one of the easier protocols

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文