View Single Post
  #1  
Old April 13th 10, 04:55 AM posted to microsoft.public.outlook.program_addins
cbukeo via OfficeKB.com
external usenet poster
 
Posts: 4
Default How can I create a new MailItem inside a user folder?

Hello All,

I am developing an Outlook 2007 addin using VisualStudio 2008 and C#. My goal
is to create an email inside a user created folder.

I successfully create the folder and a message. However, I cannot get the
message placed in the user created folder. Instead it always ends up in the
default "Drafts" folder. Is there an outlook object model call that can solve
this problem?

My code looks like this (a bit simplified):

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Folder olFolder = olParentFolder.Folders.Add("AUserFolder",
OlDefaultFolders.OlDefaultFolders.olFolderInbox);

Outlook.MailItem olMail = (Outlook.MailItem)olFolder.Items.Add(OlItemType.
olMailItem);

olMail.Subject = "Message Subject";
olMail.Body = "Message Unformatted Body";

foreach (string fromAddress in fromAddresses)
{
Outlook.Recipient olRecipient = olMail.Recipients.Add(fromAddress);
olRecipient.Type = OlMailRecipientType.olOriginator;
olRecipient.Resolve();
}

foreach (string toAddress in toAddresses)
{
Outlook.Recipient olRecipient = olMail.Recipients.Add(fromAddress);
olRecipient.Type = OlMailRecipientType.olTo;
olRecipient.Resolve();
}

olMail.Close(OlInspectorClose.olSave);

--
Message posted via http://www.officekb.com

Ads