Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > Saving or Adding MailItem to outlook draft folder is giving System.Runtime.InteropServices.COMException (0x8004011B): Unknown Error.
 

Saving or Adding MailItem to outlook draft folder is giving System.Runtime.InteropServices.COMException (0x8004011B): Unknown Error.

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.

ProgrammerX  Friday, October 09, 2009 6:41 AM

Hi,

It seems that you have changed the default data file. Now Personal folder is the default folder, it saves items in the local.

In this KB article: http://support.microsoft.com/kb/287070, exchange mailbox is located on the server, and save items in the exchange server. As you metioned, if you clear Use Cached Exchange Mode, the item cannot be save as there is no store. So it will throw an exception when saving a mail item.

Best regards,
Bessie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Tuesday, October 13, 2009 5:40 AM
We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to "Question" by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

 


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Friday, October 16, 2009 11:00 AM

You can use google to search for other answers

Custom Search

More Threads

• VSTO, Outlook 2003, vs2005 open build-in forms
• VSTO and Outlook 2007 - Use Inspector.SetCurrentFormPage to select a custom Outlook Form Region
• OleDbPermission error accessing assembly
• Cant find word 2007 Template/document in VSTO SE release
• Outlook add-in and command line arguments
• Searching Files
• During installation of a outllook addin , first prompt to user is not getting popped up (Vista).
• inserting page breaks
• Programmatically Convert .docx to .pdf
• Getting the Attachments from the Outlook Contacts