C# 如何在winforms中从outlook电子邮件获取附件? Microsoft.Office.Interop.Outlook.Application=new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MAPIFolder inBox=Application.ActiveExplorer().Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); Microsoft.Office.Interop.Outlook.Items inBoxItems=收件箱.Items; Microsoft.Office.Interop.Outlook.MailItem newEmail=null; foreach(inBoxItems中的对象集合项) { newEmail=collectionItem作为Microsoft.Office.Interop.Outlook.MailItem; if(newEmail!=null) { 如果(newEmail.Attachments.Count>0) { 对于(inti=1;iintextractfileparentid=pkUniqueId; List-extractFileList=lts; MsgReader.Outlook.Storage.Message=新的MsgReader.Outlook.Storage.Message(文件名); foreach(message.Attachments中的var附件) { 字符串文件名=string.Empty; pkUniqueId=pkUniqueId+1; if(attachment.GetType()==typeof(MsgReader.Outlook.Storage.attachment)) { var attach=(MsgReader.Outlook.Storage.Attachment)附件; fileName=Path.Combine(tempPath,(attach.fileName); File.writealBytes(文件名,attach.Data); 添加(新的ZipExtracFile{pkUniqueId=pkUniqueId,fileName=fileName,parentId=extractFileParentId}); if(Path.GetExtension(fileName).ToLower()==“.msg”) { ExtractMsgFile(文件名,ref-pkUniqueId,ref-tempPath,lts); } } } message.Dispose();

C# 如何在winforms中从outlook电子邮件获取附件? Microsoft.Office.Interop.Outlook.Application=new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MAPIFolder inBox=Application.ActiveExplorer().Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); Microsoft.Office.Interop.Outlook.Items inBoxItems=收件箱.Items; Microsoft.Office.Interop.Outlook.MailItem newEmail=null; foreach(inBoxItems中的对象集合项) { newEmail=collectionItem作为Microsoft.Office.Interop.Outlook.MailItem; if(newEmail!=null) { 如果(newEmail.Attachments.Count>0) { 对于(inti=1;iintextractfileparentid=pkUniqueId; List-extractFileList=lts; MsgReader.Outlook.Storage.Message=新的MsgReader.Outlook.Storage.Message(文件名); foreach(message.Attachments中的var附件) { 字符串文件名=string.Empty; pkUniqueId=pkUniqueId+1; if(attachment.GetType()==typeof(MsgReader.Outlook.Storage.attachment)) { var attach=(MsgReader.Outlook.Storage.Attachment)附件; fileName=Path.Combine(tempPath,(attach.fileName); File.writealBytes(文件名,attach.Data); 添加(新的ZipExtracFile{pkUniqueId=pkUniqueId,fileName=fileName,parentId=extractFileParentId}); if(Path.GetExtension(fileName).ToLower()==“.msg”) { ExtractMsgFile(文件名,ref-pkUniqueId,ref-tempPath,lts); } } } message.Dispose();,c#,C#,这用于从.msg文件文档中获取文档,带有多级.msg文件,可以在特定位置下载。为此,只需添加MsgReader.dllint-extractFileParentId=pkUniqueId; List-extractFileList=lts; MsgReader.Outlook.Storage.Message=新的MsgReader.Outlook.Storage.Message(文件名); foreach(message.Attachments中的var附件) { 字符串文件名=string.E

这用于从.msg文件文档中获取文档,带有多级.msg文件,可以在特定位置下载。为此,只需添加MsgReader.dll

int-extractFileParentId=pkUniqueId;
List-extractFileList=lts;
MsgReader.Outlook.Storage.Message=新的MsgReader.Outlook.Storage.Message(文件名);
foreach(message.Attachments中的var附件)
{
字符串文件名=string.Empty;
pkUniqueId=pkUniqueId+1;
if(attachment.GetType()==typeof(MsgReader.Outlook.Storage.attachment))
{
var attach=(MsgReader.Outlook.Storage.Attachment)附件;
fileName=Path.Combine(tempPath,(attach.fileName);
File.writealBytes(文件名,attach.Data);
添加(新的ZipExtracFile{pkUniqueId=pkUniqueId,fileName=fileName,parentId=extractFileParentId});
if(Path.GetExtension(fileName).ToLower()==“.msg”)
{
ExtractMsgFile(文件名,ref-pkUniqueId,ref-tempPath,lts);
}
}
}
message.Dispose();
这用于从“.msg”文件获取文档,带有多级“.msg”文件,可以在特定位置下载。为此,只需添加MsgReader.dll

Microsoft.Office.Interop.Outlook.Application Application = new Microsoft.Office.Interop.Outlook.Application();

                    Microsoft.Office.Interop.Outlook.MAPIFolder inBox = Application.ActiveExplorer().Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                    Microsoft.Office.Interop.Outlook.Items inBoxItems = inBox.Items;
                    Microsoft.Office.Interop.Outlook.MailItem newEmail = null;

                    foreach (object collectionItem in inBoxItems)
                    {
                        newEmail = collectionItem as Microsoft.Office.Interop.Outlook.MailItem;
                        if (newEmail != null)
                        {
                            if (newEmail.Attachments.Count > 0)
                            {
                                for (int i = 1; i <= newEmail
                                    .Attachments.Count; i++)
                                {
                                    newEmail.Attachments[i].SaveAsFile
                                        (@"C:\TestFileSave\" +
                                        newEmail.Attachments[i].FileName);
                                }
                            }
                        }
                    }
 int extractFileParentId = pkUniqueId;
        List<ZipExtracFile> extractFileList = lts;
        MsgReader.Outlook.Storage.Message message = new MsgReader.Outlook.Storage.Message(fileNames);

        foreach (var attachment in message.Attachments)
        {
            string fileName = string.Empty;
            pkUniqueId = pkUniqueId + 1;
            if (attachment.GetType() == typeof(MsgReader.Outlook.Storage.Attachment))
            {
                var attach = (MsgReader.Outlook.Storage.Attachment)attachment;
                fileName = Path.Combine(tempPath, (attach).FileName);

                File.WriteAllBytes(fileName, attach.Data);
                extractFileList.Add(new ZipExtracFile { pkUniqueId = pkUniqueId, fileName = fileName, parentId = extractFileParentId });

                if(Path.GetExtension(fileName).ToLower() == ".msg")
                {
                    ExtractMsgFile(fileName, ref pkUniqueId, ref tempPath, lts);
                }
            }
        }
        message.Dispose();