Access Outlook from C#http://forums.asp.net/t/1174921.aspx/1?Access+Outlook+from+C+Mon, 29 Oct 2007 18:52:41 -040011749211976193http://forums.asp.net/p/1174921/1976193.aspx/1?Access+Outlook+from+C+Access Outlook from C# <p>Hi All,</p> <p>I am trying to read all the emails from Outlook mail folder. I was able to access the folder that I want and loop through the messages; however when I debug the application I can notice that huge number of email are retreived as nulls! although I can access all the information for a little number of emails in the folder.</p> <p>Regards</p> 2007-10-26T15:25:33-04:001976275http://forums.asp.net/p/1174921/1976275.aspx/1?Re+Access+Outlook+from+C+Re: Access Outlook from C# <p>HI;</p> <p>The null messages are the messages that have been archived away using compact. When was the last time you did a compact on your outlook?</p> <p>Regards</p> <p>Shivam&nbsp;</p> 2007-10-26T16:19:43-04:001976290http://forums.asp.net/p/1174921/1976290.aspx/1?Re+Access+Outlook+from+C+Re: Access Outlook from C# <p>Hi mate,</p> <p>Actually all the emails that I am reading from outlook are in one folder. None of them is archived</p> <p>Regards</p> <p>&nbsp;</p> 2007-10-26T16:27:43-04:001978752http://forums.asp.net/p/1174921/1978752.aspx/1?Re+Access+Outlook+from+C+Re: Access Outlook from C# Hello mr.aspdotnet, could your post the small but completed codesnipped demonstrating how u extract the mail messages? m&gt; Hi All, m&gt; m&gt; I am trying to read all the emails from Outlook mail folder. I was m&gt; able to access the folder that I want and loop through the messages; m&gt; however when I debug the application I can notice that huge number of m&gt; email are retreived as nulls! although I can access all the m&gt; information for a little number of emails in the folder. m&gt; m&gt; Regards m&gt; 2007-10-29T10:32:44-04:001978772http://forums.asp.net/p/1174921/1978772.aspx/1?Re+Access+Outlook+from+C+Re: Access Outlook from C# <p>Outlook._Application appOutlook = new Outlook.Application();</p> <p>Outlook.NameSpace outlookNS = appOutlook.GetNamespace(&quot;MAPI&quot;);</p> <p>outlookNS.Logon(&quot;&quot;, null, null, null);</p> <p>string statInfo;</p> <p>DateTime today = DateTime.Today;</p> <p>int eMailsToday = 0;</p> <p>int eMailsThisMonth = 0;</p> <p>&nbsp;</p> <p>MAPIFolder inboxFolder = outlookNS.Folders[1].Folders[&quot;ErrorsStudy&quot;];</p> <p>&nbsp;</p> <p>foreach (object item in inboxFolder.Items)</p> <p>{</p> <p>Outlook.MailItem mi = item as MailItem;</p> <p>if (mi != null)</p> <p>{</p> <p>if (mi.ReceivedTime.Day == today.Day)</p> <p>eMailsToday&#43;&#43;;</p> <p>if (mi.ReceivedTime.Month == today.Month)</p> <p>eMailsThisMonth&#43;&#43;;</p> <p>}</p> <p>}</p> <p>&nbsp;</p> <p>statInfo = string.Format(&quot;E-mails received today: {0}\n&quot;,eMailsToday);</p> <p>statInfo &#43;= string.Format(&quot;E-mails received this Month: {0}&lt;br /&gt;&quot;,eMailsThisMonth); </p> <p>Response.Write(statInfo);</p> <p>&nbsp;</p> <p>outlookNS.Logoff();</p> <p>outlookNS = null;</p> <p>appOutlook = null;</p> <p>Regards</p> 2007-10-29T10:42:11-04:001978821http://forums.asp.net/p/1174921/1978821.aspx/1?Re+Access+Outlook+from+C+Re: Access Outlook from C# Hello mr.aspdotnet, Everything ok with your code. I've just checked on Outlook 2007 and all emails are extracted normally Make sure that you download &quot;full&quot; message, not the &quot;message header&quot; in your outlook settings (the right bottom corner of the outlook status bar) m&gt; Outlook._Application appOutlook = new Outlook.Application(); m&gt; m&gt; Outlook.NameSpace outlookNS = appOutlook.GetNamespace(&quot;MAPI&quot;); m&gt; m&gt; outlookNS.Logon(&quot;&quot;, null, null, null); m&gt; m&gt; string statInfo; m&gt; m&gt; DateTime today = DateTime.Today; m&gt; m&gt; int eMailsToday = 0; m&gt; m&gt; int eMailsThisMonth = 0; m&gt; m&gt; MAPIFolder inboxFolder = outlookNS.Folders[1].Folders[&quot;ErrorsStudy&quot;]; m&gt; m&gt; foreach (object item in inboxFolder.Items) m&gt; m&gt; { m&gt; m&gt; Outlook.MailItem mi = item as MailItem; m&gt; m&gt; if (mi != null) m&gt; m&gt; { m&gt; m&gt; if (mi.ReceivedTime.Day == today.Day) m&gt; m&gt; eMailsToday&#43;&#43;; m&gt; m&gt; if (mi.ReceivedTime.Month == today.Month) m&gt; m&gt; eMailsThisMonth&#43;&#43;; m&gt; m&gt; } m&gt; m&gt; } m&gt; m&gt; statInfo = string.Format(&quot;E-mails received today: m&gt; {0}\n&quot;,eMailsToday); m&gt; m&gt; statInfo &#43;= string.Format(&quot;E-mails received this Month: {0}<br> /&gt;&quot;,eMailsThisMonth); m&gt; m&gt; Response.Write(statInfo); m&gt; m&gt; outlookNS.Logoff(); m&gt; m&gt; outlookNS = null; m&gt; m&gt; appOutlook = null; m&gt; m&gt; Regards m&gt; 2007-10-29T11:17:29-04:001979722http://forums.asp.net/p/1174921/1979722.aspx/1?Re+Access+Outlook+from+C+Re: Access Outlook from C# <p>Hi,</p> <p>Actually I am working with Outlook 2003. The problem is that I can access all the message attributes, but for some reason after some emails it starts to read null values. That is the whole object is null not its attributes. For example if I have 200 emails to read then I will be able to read 100 only and the rest will be read as nulls'.</p> <p>Regards</p> 2007-10-29T18:52:41-04:00