Last post Sep 20, 2009 02:25 PM by Sun!L Kum@r
Feb 28, 2008 11:10 AM|matthizou|LINK
I do a simple program to count how many unread emails are present in a mailbox (on a server exchange). My first step and my question are :
How can I retrieve emails from an exchange mailbox using C#?
In all my research, I am finding how to send emails but not retrieve them.
I don't want to use third party APIs and would like to keep it as simple as possible...
Can some one please point me in the right direction?
Thanks in advance...
Feb 28, 2008 11:49 PM|ghinx|LINK
using Outlook = Microsoft.Office.Interop.Outlook; //you need to add the Microsoft Office 11.0 Object Library to use this. mine is version 11 you might have an older or later version.
Outlook.Application outlook = new Outlook.ApplicationClass();
Outlook.NameSpace ns = outlook.GetNamespace("Mapi");
object _missing = Type.Missing;
ns.Logon(_missing, _missing, false, true);
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
int unread = inbox.UnReadItemCount;
foreach (Outlook.MailItem mail in inbox.Items)
string s = mail.Subject;
Feb 29, 2008 06:35 AM|matthizou|LINK
Thanks Ghinx. That's a good piece of code.
I guess this library connects Outlook and uses one of my saved profiles to connect the exchange server.
But I want to access the inbox of any user ( I have the username and password).
I read somewhere that "If you need to get data from another user's Exchange mailbox, you can use CDO (not officially supported in .NET, but people have been using it) or WebDAV"
Does someone have a simple piece of code to do that in CDO or/and webdav and Exchange 2003?
Feb 29, 2008 06:59 PM|AdvanIntel|LINK
Mar 02, 2008 01:37 PM|matthizou|LINK
"try using the respective protocol"... what do you mean? Let's say I can connect the exchange server using POP3. What API/technology should I use? Do you have a code sample?
Mar 04, 2008 06:00 PM|AdvanIntel|LINK
Mar 05, 2008 04:32 AM|matthizou|LINK
I found some good articles to do POP3 with C#:
You can download some code here, I tried it and it works fine :
May 05, 2009 06:44 AMfirstname.lastname@example.org|LINK
Could you please let me know how to retrieve emails from mailbox other than default mailbox?
Thanks in advance!
Sep 20, 2009 02:25 PM|Sun!L Kum@r|LINK
Check this out
I am providing flexibility to enter pop3 id and password from user
and on button click write this
lit_Status.Text = strReader.ReadLine() +
WriteBuffer = enc.GetBytes(
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
lit_Status.Text += strReader.ReadLine() +
ListMessage = strReader.ReadLine();
lit_Status.Text += ListMessage +