Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   How can I create a new MailItem inside a user folder? (http://www.outlookbanter.com/add-ins-outlook/101800-how-can-i-create-new.html)

cbukeo via OfficeKB.com April 13th 10 04:55 AM

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


Ken Slovak - [MVP - Outlook] April 13th 10 02:57 PM

How can I create a new MailItem inside a user folder?
 
New messages are always created in Drafts. If you want to move it to the
desired folder after the message is created in Drafts you can do so.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"cbukeo via OfficeKB.com" u59160@uwe wrote in message
news:a673768e8b499@uwe...
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



cbukeo via OfficeKB.com April 15th 10 06:19 PM

How can I create a new MailItem inside a user folder?
 
Thanks! Very simple solution. Can't help but smile and wonder how come I
could not think about this?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...ddins/201004/1


cbukeo via OfficeKB.com April 16th 10 05:58 PM

How can I create a new MailItem inside a user folder?
 
Ken,
Now I am able to move messages around within folders. However, the messages
stay as drafts. How can I set their sent status to true? This is also causing
problems if I try to set them as tasks. OOM throws an exception complaining
that a draft message cannot be set as a task.
Many thanks again
Buke

Ken Slovak - [MVP - Outlook] wrote:
New messages are always created in Drafts. If you want to move it to the
desired folder after the message is created in Drafts you can do so.

Hello All,

[quoted text clipped - 37 lines]

olMail.Close(OlInspectorClose.olSave);


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...ddins/201004/1


Ken Slovak - [MVP - Outlook] April 19th 10 02:38 PM

How can I create a new MailItem inside a user folder?
 
What do you mean "set a message as a task"? They are 2 different objects and
MessageClass's. If you want to create a task item create one and copy any
property values from your email message item to the task that you want (such
as Subject or body text, etc.).

You cannot use the Outlook object model to create an item that looks sent.
You can use Extended MAPI or a 3rd party library, Redemption
(www.dimastr.com/redemption) to do that. You'd have to set various
properties such as sender addresses and so on to the values you want as well
as the Sent property before the new item you create is saved the first time.
There's a code sample showing that at the Redemption Web site.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"cbukeo via OfficeKB.com" u59160@uwe wrote in message
news:a6a004c1c7866@uwe...
Ken,
Now I am able to move messages around within folders. However, the
messages
stay as drafts. How can I set their sent status to true? This is also
causing
problems if I try to set them as tasks. OOM throws an exception
complaining
that a draft message cannot be set as a task.
Many thanks again
Buke




All times are GMT +1. The time now is 12:25 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com