问题描述
我正在尝试从 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!