A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How can I create a new MailItem inside a user folder?



 
 
Thread Tools Search this Thread Display Modes
  #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

  #2  
Old April 13th 10, 02:57 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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


  #3  
Old April 15th 10, 06:19 PM 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?

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

  #4  
Old April 16th 10, 05:58 PM 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?

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

  #5  
Old April 19th 10, 02:38 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a new Outlook MailItem in an Outlook folder(not a draft) Sanjeev Outlook - Using Forms 2 March 22nd 10 10:46 AM
Create a forwarded mailitem that has a flag but requires user to s mkp1702 Outlook and VBA 1 March 10th 08 05:44 AM
Create and Get user-defined fields in folder ck Add-ins for Outlook 10 January 11th 08 05:02 PM
How to create user-defined fields in Organizational Forms Library folder? [email protected] Add-ins for Outlook 3 March 15th 07 09:07 PM
How can I create a MailItem that displays like a received MailItem ? Clive Outlook - Using Forms 0 February 27th 06 04:14 PM


All times are GMT +1. The time now is 08:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.