[英]C# Outlook 2010 AddIn Display form with Background Image when new Email is received
[英]How can I get the received mails (or any other items ) in an addin C # for outlook 2010
我嘗試以下代碼:
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
mapiNameSpace.Logon(null, null, false, false);
mapiNameSpace.Logon("MyEmailID", "PasswordOfMyEmail", Missing.Value, true);
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
MessageBox.Show(myInbox.Items.Count + "");
但是MessageBox向我顯示0(myInbox.Items.Count)。
因此,也許我無法訪問我的Outlook帳戶!
我使用Visual Studio 2010。
有人能幫助我嗎 ?
首先,如果您在外接程序中,則永遠不要創建Outlook.Application對象的新實例-您已經通過全局變量將其公開給外接程序。
其次,不要調用登錄-Outlook將為您完成此操作。 該方法確實適用於外部應用程序,而不適用於插件。
第三,調用一次登錄,配置文件名稱為null。 如果您不想傳遞可選參數,請傳遞Missing.Value,而不是null。 而第二次調用Logon(為什么需要它?)將完全無效。 無論如何都無法傳遞任何電子郵件-參數必須是配置文件名稱,如“控制面板” |“控制面板”中所示。 郵件| 顯示個人資料。
最重要的是,您何時撥打該電話? 您的收件箱中實際上是否包含任何消息? 還是它是全新的配置文件,而Outlook尚未有機會從郵箱下載郵件?
因此您可以使用:
Explorer currentExplorer = Globals.ThisAddIn.Application.ActiveExplorer();
MAPIFolder myInbox = Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder;
try
{
if ( (currentExplorer != null) && (currentExplorer.Selection != null) && (currentExplorer.Selection.Count > 0) )
{
object item = currentExplorer.Selection[1];
if (item is MailItem)
{
MailItem mailItem = item as MailItem;
MessageBox.Show(myInbox.Items.Count + "");
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.