gpt4 book ai didi

.net - 电子邮件附件的自动处理

转载 作者:可可西里 更新时间:2023-11-01 09:32:39 24 4
gpt4 key购买 nike

我想编写一个应用程序(最有可能用 C# 编写)来检查特定帐户的电子邮件、检测附件并将它们分离到文件夹中进行处理。

是否有标准的 .NET 类来执行这些任务?如果没有,我还能使用什么?

应用程序将作为服务运行。

最佳答案

虽然 BCL 中没有用于下载电子邮件的 API,只能用于发送,但有一个非常受欢迎的 API,现在是 Microsoft 推荐的用于发送和接收电子邮件的库,它支持 POP3、IMAP、SMTP。 https://github.com/jstedfast/MailKit

detects attached files and detaches them to a folder for processing

我假设您的意思是将文件下载到目录中。幸运的是,使用 MailKit 这很容易做到,库的作者在这里写了一个例子:https://stackoverflow.com/a/36229918/2595033

(代码取自链接)

foreach (var attachment in message.Attachments) {
using (var stream = File.Create ("fileName")) {
if (attachment is MessagePart) {
var part = (MessagePart) attachment;

part.Message.WriteTo (stream);
} else {
var part = (MimePart) attachment;

part.ContentObject.DecodeTo (stream);
}
}
}

The application will run as a service.

这个也很容易做到,你需要写一个Windows Service。有很多关于用 C# 编写的资源。在 Visual Studio 中还有一个模板。

enter image description here

关于.net - 电子邮件附件的自动处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44244124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com