从C#.Net 3.5导入Outlook 2007形式的附件 [英] Import attachments form outlook 2007 from C#.Net 3.5

查看:79
本文介绍了从C#.Net 3.5导入Outlook 2007形式的附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我编写了用于从Outlook 2007导入未读电子邮件的C#应用​​程序,可以将发件人名称,发件人邮件地址,主题和正文导入数据网格视图,如下所示:

Hi,
I wrote C# application for import unread e-mails from outlook 2007, I could import sender name, sender mail address,subject and body to data grid view as following

UnreadEmails mail = new UnreadEmails(); mail.SenderName = (mailItem.UnRead == false) ? string.Empty : mailItem.SenderName; mail.SenderAddress = (mailItem.UnRead == false) ? string.Empty : mailItem.SenderEmailAddress; mail.Subject = (mailItem.UnRead == false) ? string.Empty : mailItem.Subject; mail.BodyContent = (mailItem.UnRead == false) ? string.Empty : mailItem.Body; 
// mail.AttachmentContent = (mailItem.UnRead == false) ? string.Empty : mailItem.Attachments.Session.OpenSharedItem; emails.Add(mail);



UnreadEmails 是一个单独的类.但是找不到导入附件的方法(word pdf ppt excel),因为我需要它作为我的过滤器,请帮我解决一下



UnreadEmails is a separte class. but couldn''t find a way to import attachments (word pdf ppt excel) because i need it for my filter pls help me about it

推荐答案

我找到了此代码在网络上,这可能会有所帮助

I found this code on net, this might help

Outlook.Application app = new Outlook.ApplicationClass();
Outlook.NameSpace NS = app.GetNamespace("MAPI");
Outlook.MAPIFolder inboxFld = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);



这将使您可以访问inboxFld,从而可以循环访问收件箱中的内容!您还可以根据需要更改此设置以遍历便笺或日历条目,任务等.


例如,要遍历您的邮件,您可以执行以下操作:




This will give you access to inboxFld, which will allow you to iterate through the contents of the inbox! You can also change this to iterate through notes, or through calendar entries, tasks, etc. as you want.


For example, to iterate through your mail you can do:


foreach(Outlook.MailItem t in inboxFld.Items)
{
 Now you can loop through the attachments as, 


    foreach(Outlook.Attachment Atmt in t.Attachments){
       ''save the attachment to some filename, just for ex., c:\test.doc
        Atmt.SaveAsFile "C:\test.doc"
    } 


}


这篇关于从C#.Net 3.5导入Outlook 2007形式的附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆