gpt4 book ai didi

c# - 保存附件

转载 作者:行者123 更新时间:2023-11-30 18:11:04 25 4
gpt4 key购买 nike

我正在尝试监控我的 Outlook 收件箱,因此每当收到带有附件的新电子邮件时,我都会将附件保存到其他位置。谁能帮帮我?

最佳答案

这不是一个完整的解决方案,但它描述了您将在 Outlook API 中使用的一些基本工具。

来自 Access Outlook Emails with ASP.NET, C# :

using Outlook;

Outlook.Application oOutlook;
Outlook.NameSpace oNs;
Outlook.MAPIFolder oFldr;
long iAttachCnt;

try
{
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace(”MAPI”);

//getting mail folder from inbox
oFldr = oNs.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Response.Write(”Total Mail(s) in Inbox :” + oFldr.Items.Count + “<br>”);
Response.Write(”Total Unread items = ” + oFldr.UnReadItemCount);
foreach (Outlook.MailItem oMessage in oFldr.Items)
{
StringBuilder str = new StringBuilder();
str.Append(”<table style=’border:1px solid gray;font-family:Arial;font-size:x-small;width:80%;’ align=’center’><tr><td style=’width:20%;’><b>Sender :</b></td><td>”);
str.Append(oMessage.SenderEmailAddress.ToString() + “</td></tr>”);
//basic info about message
str.Append(”<tr><td><b>Date :</b></td><td>” + oMessage.SentOn.ToShortDateString() + “</td></tr>”);
if (oMessage.Subject != null)
{
str.Append(”<tr><td><b>Subject :</b></td><td>” + oMessage.Subject.ToString() + “</td></tr>”);
}
//reference and save all attachments

iAttachCnt = oMessage.Attachments.Count;
if (iAttachCnt > 0)
{
for (int i = 1; i <= iAttachCnt; i++)
{
str.Append(”<tr><td><b>Attachment(” + i.ToString() + “) :</b></td><td>” + oMessage.Attachments[i].FileName + “</td></tr>”);
}
}
str.Append(”</table><br>”);
Response.Write(str.ToString());

}

}
catch (System.Exception ex)
{
Response.Write(”Execption generated:” + ex.Message);
}
finally
{
GC.Collect();
oFldr = null;
oNs = null;
oOutlook = null;

}

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

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