private List GetEmailsFromFolder(string folderName) { List emails = null; object missing = System.Reflection.Missing.Value; try { Outlook.MAPIFolder fldEmails = null; emails = new List(); Outlook._Application outlookObj = new Outlook.Application(); if (folderName == "Default") { fldEmails = (Outlook.MAPIFolder)outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); } else { Outlook.MAPIFolder emailFolder = (Outlook.MAPIFolder) outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); foreach (Outlook.MAPIFolder subFolder in emailFolder.Folders) { if (subFolder.Name == folderName) { fldEmails = subFolder; break; } } } foreach (Microsoft.Office.Interop.Outlook._MailItem mailItem in fldEmails.Items) { if (mailItem.UnRead) { 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 = MessageBox.Show(mailItem.Body); mail.Attachment = "View Attachments"; emails.Add(mail); } } }
private List GetEmailsFromFolder(string folderName) { List emails = null; object missing = System.Reflection.Missing.Value; try { Outlook.MAPIFolder fldEmails = null; emails = new List(); Outlook._Application outlookObj = new Outlook.Application(); if (folderName == "Default") { fldEmails = (Outlook.MAPIFolder)outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); } else { Outlook.MAPIFolder emailFolder = (Outlook.MAPIFolder) outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); foreach (Outlook.MAPIFolder subFolder in emailFolder.Folders) { if (subFolder.Name == folderName) { fldEmails = subFolder; break; } } } foreach (Microsoft.Office.Interop.Outlook._MailItem mailItem in fldEmails.Items) { if (mailItem.UnRead) { 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 = MessageBox.Show(mailItem.Body); mail.Attachment = "View Attachments"; emails.Add(mail); }
i wrote above method to import unread mail details to data gride from outlook 2007. it is working perfectlly but because mail.BodyContent = MessageBox.Show(mailItem.Body); that code it give mail body without stopping what i need to do is i need to open perticuler body when i click relavent button in the data gride .. pls tell me how can i do it i am haveing buttons as mail body column thank you
mail.BodyContent = MessageBox.Show(mailItem.Body);