本文介绍了C#Winforms:使用多个邮箱访问Outlook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从C#/Winforms访问Outlook邮箱.我的用户个人资料可以访问两个单独的邮箱.我该如何编码,使其仅从某个邮箱中提取?
I'm trying to access an Outlook Mailbox from C# / Winforms. I have two separate mailboxes that my user profile can access. How can i code it so that it only pulls from a certain mailbox?
这是我目前拥有的,但是它只会从我的默认帐户邮箱中提取信息.
Here's what I have currently, but it only pulls the info from my default account mailbox.
try
{
OutLook.Application oApp = new OutLook.Application();
OutLook.NameSpace oNS = (OutLook.NameSpace)oApp.GetNamespace("MAPI");
oNS.Logon(Missing.Value, Missing.Value, false, true);
OutLook.MAPIFolder theInbox = oNS.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderInbox);
int count = theInbox.UnReadItemCount;
inboxLabel.Text = inboxLabel.Text + " " + count.ToString();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
我还需要告知某些文件夹以及收件箱(如上).
I also need to tell it certain folders along with the inbox (like above).
非常感谢您的帮助.
推荐答案
我终于弄清楚了如何指定要打开的邮箱.我会将其发布在这里,以供将来使用.
I finally figured out how to designate which mailbox I wanted to open. I'll post it here for others to use in the future.
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");
oNS.Logon(Missing.Value, Missing.Value, false, true);
Outlook.MAPIFolder theInbox = oNS.Folders["Mailbox - Name Here"].Folders["Inbox"];
....Do you want with that Folder here....
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
希望这对其他人有帮助:D
Hope this helps anyone else :D
这篇关于C#Winforms:使用多个邮箱访问Outlook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!