MAPI.Recipients recipients = (MAPI.Recipients)message.Recipients;
MAPI.Recipient recipient = (MAPI.Recipient)recipients.get_Item(1);
MAPI.AddressEntry addressEntry = (MAPI.AddressEntry)recipient.AddressEntry;
string emailAddress = addressEntry.Address.ToString();
Tuesday, July 29, 2008
Friday, July 25, 2008
MAPI - Connecting to a mailbox and looping through the inbox
Note: You'll need to reference the COM library "Microsoft CDO 1.21 Library"
MAPI.Session session = new MAPI.Session();
string profileInfo = "EXCHANGE_SERVER" + "\n" + "MAILBOX_NAME";
session.Logon("PROFILE_NAME", System.Reflection.Missing.Value, true, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, profileInfo);
// Get the folder
MAPI.Folder inboxFolder = session.Inbox as MAPI.Folder;
// Enumerate messages
MAPI.Messages messages = (MAPI.Messages)inboxFolder.Messages;
MAPI.Message message = (MAPI.Message)messages.GetFirst(null);
while (message != null)
{
// do stuff with the message
try
{
message = (MAPI.Message)messages.GetNext();
if (message != null)
{
textBox1.Text += message.Subject.ToString();
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message.ToString();
return;
}
}
session.Logoff();
}
MAPI.Session session = new MAPI.Session();
string profileInfo = "EXCHANGE_SERVER" + "\n" + "MAILBOX_NAME";
session.Logon("PROFILE_NAME", System.Reflection.Missing.Value, true, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, profileInfo);
// Get the folder
MAPI.Folder inboxFolder = session.Inbox as MAPI.Folder;
// Enumerate messages
MAPI.Messages messages = (MAPI.Messages)inboxFolder.Messages;
MAPI.Message message = (MAPI.Message)messages.GetFirst(null);
while (message != null)
{
// do stuff with the message
try
{
message = (MAPI.Message)messages.GetNext();
if (message != null)
{
textBox1.Text += message.Subject.ToString();
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message.ToString();
return;
}
}
session.Logoff();
}
Subscribe to:
Posts (Atom)