I think I figured this out using this code,
oApp = new Microsoft.Office.Interop.Outlook.Application();
oNS = (Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI");
oNS.Logon(null, null, false, false);
QSourceFolder = oNS.Folders["qsource inc"];
string folderName = "Clutter";
try
{
oSubfolder = QSourceFolder.Folders[folderName];
foreach (Microsoft.Office.Interop.Outlook.MailItem mailItem in oSubfolder.Items)
subject = mailItem.Subject;
but when I try to loop through the emails in this folder I get the following error message:
I am trying to figure out how can I access a specific folder using C# that is part of another email account other than my own. I have the ability to see emails that are sent to the widget inc email account, and I want to programmatically examine any emails that are sent to it. Specifically I want to see any emails that get kicked back due to a bad email address, and these are being put in the Clutter folder.
You are assuming that you can only have MailItem
objects in a the folder. You can have MailItem
, ReportItem
, MeetingItem
etc. - use a generic "object" instead of MailItem and use the " as
" operator to cast to a specific interface with the subsequent check for null.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.