Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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
Posted
Updated 26-May-10 16:00pm
v2

1 solution

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);


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"
    } 


}
 
Share this answer
 
Comments
Kasunmit 26-May-10 22:26pm    
thank you very much for help i ll try it ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900