gpt4 book ai didi

c# - 使用 Mailkit 通过 IMAP 保存附件

转载 作者:行者123 更新时间:2023-11-30 19:56:52 24 4
gpt4 key购买 nike

我需要在 Google IMAP 服务器上找到一封特定的电子邮件,然后保存电子邮件中的附件。除了确定附件的文件名的部分外,我想我已经弄清楚了。

下面是我目前的代码,我希望有人能指出正确的方向来确定文件名。

我用 Google 搜索了 SO'd但无法使用附件方法找到一些东西。

internal class MailKitHelper
{
private void SaveAttachementsForMessage(string aMessageId)
{
ImapClient imapClient = new ImapClient();
imapClient.Connect("imap.google.com", 993, SecureSocketOptions.Auto);
imapClient.Authenticate("xxxx", "xxxx");

HeaderSearchQuery searchCondition = SearchQuery.HeaderContains("Message-Id", aMessageId);
imapClient.Inbox.Open(FolderAccess.ReadOnly);
IList<UniqueId> ids = imapClient.Inbox.Search(searchCondition);

foreach (UniqueId uniqueId in ids)
{
MimeMessage message = imapClient.Inbox.GetMessage(uniqueId);

foreach (MimeEntity attachment in message.Attachments)
{
attachment.WriteTo("WhatIsTheFileName"); //How do I determine the file name
}
}
}
}

最佳答案

获胜者是......

attachment.ContentDisposition.FileName

关于c# - 使用 Mailkit 通过 IMAP 保存附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32478059/

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