In the Microsoft outlook 2007, we do have two data files
1. Exchange Mailbox
2. Personal folder (.pst file)
If we execute below code, when data file “Personal folder (.pst file)” is selected as default then things are working fine.
public void OpenMSG()
{
OfficeOutlook.Application objOutlook = null;
OfficeOutlook.NameSpace objFolder = null;
OfficeOutlook.Explorer objExplorer = null;
try
{
objOutlook = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application") as OfficeOutlook.Application;
objFolder = objOutlook.GetNamespace("MAPI");
}
catch
{
objOutlook = new OfficeOutlook.Application();
objFolder = objOutlook.GetNamespace("MAPI");
}
objExplorer = objOutlook.Application.ActiveExplorer();
OfficeOutlook._Explorer msOutlookExplorer = objExplorer as OfficeOutlook._Explorer;
if (msOutlookExplorer != null)
{
msOutlookExplorer.Activate();
OfficeOutlook.MAPIFolder draftsFolder = (OfficeOutlook.MAPIFolder)objOutlook.Session.GetDefaultFolder(OfficeOutlook.OlDefaultFolders.olFolderDrafts);
msOutlookExplorer.SelectFolder(draftsFolder);
OfficeOutlook.MailItem mailItem = (OfficeOutlook.MailItem)objOutlook.CreateItemFromTemplate
(textBox1.Text, draftsFolder);
//either of the statement is giving error '-2147221221'
//************** Exception Text **************
//System.Runtime.InteropServices.COMException (0x8004011B): Unknown Error.
//at Microsoft.Office.Interop.Outlook._MailItem.Save()
mailItem.Save();
mailItem.Move(draftsFolder);
mailItem.Display(false);
}
}
But if we execute same code when data file “Exchange Mailbox” is selected as default then we are getting below error.
//************** Exception Text **************
//System.Runtime.InteropServices.COMException (0x8004011B): Unknown Error.
//at Microsoft.Office.Interop.Outlook._MailItem.Save()
Specifically in this case if we check “Tools->AccountSettings->Email Tab->Change->’Use Cached Exchange Mode’" then code is not giving error.
Can any one please help, why we are getting this error? Is any workaround available for this.
Any help in this area would be highly appreciated.