Hi,
I have a situation where I want to modify an existing item in Outlook,
but I cant get the recipients to work properly when using Redemption.
First I create a new mail item, add some properties (like subject,
recipients etc), get hold of the EntryID and exit.
Later on I reconnect and find the mailItem using GetItemFromID and
start modifying this Item.
Changing the Subject works just fine, but I cant seem to get the
Recipients modified correctly.
When I add a recipient it is apparently added, using OutlookSpy to
view the "CurrentItem.To" property I can see all my recipients.
However, the ones I added when I modified the Item is not visible in
Outlook and if I manually enter a new mailaddress (in Outlook), the
ones I added in the modification code disappears from the
"CurrentItem.To" property in OutlookSpy as well.
If I use Outlook directly (no Redemption code), I can get this
working, but I dont want the Security message box, so it is not really
an alternative.
I created a small sample program that demonstrates this problem:
using Outlook = Microsoft.Office.Interop.Outlook;
using Interop.Redemption;
private void main()
{
string entryID = RedemptionCreateTestMail();
RedemptionAddRecipient(entryID);
}
private string RedemptionCreateTestMail()
{
Outlook.Application olApp = new Outlook.Application();
Outlook.NameSpace olNS =
(Outlook.NameSpace)olApp.GetNamespace("MAPI");
olNS.Logon("", "", false, true);
Interop.Redemption.SafeMailItem safeItem = new
SafeMailItem();
Outlook.MailItem mailItem =
(Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
safeItem.Item = mailItem;
safeItem.Recipients.Add("xxx@zzz.zz");
safeItem.Recipients.ResolveAll();
mailItem.Subject = "Mail Created";
mailItem.Save();
mailItem.Display(false);
string entryID = mailItem.EntryID;
mailItem = null;
safeItem = null;
olNS.Logoff();
olNS = null;
olApp = null;
return entryID;
}
private void RedemptionAddRecipient(string entryID)
{
Outlook.Application olApp = new Outlook.Application();
Outlook.NameSpace olNS =
(Outlook.NameSpace)olApp.GetNamespace("MAPI");
olNS.Logon("", "", false, true);
string storeID =
olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).StoreID;
Outlook.MailItem mailItem =
(Outlook.MailItem)olNS.GetItemFromID(entryID, storeID);
Interop.Redemption.SafeMailItem safeItem = new
SafeMailItem();
safeItem.Item = mailItem;
safeItem.Recipients.Add("yyy@zzz.zz");
safeItem.Recipients.ResolveAll();
mailItem.Subject = "Attached to mail: " + entryID;
mailItem.Save();
mailItem.Display(false);
mailItem = null;
safeItem = null;
olNS.Logoff();
olNS = null;
olApp = null;
}
Bjorn Tore
Dmitry Streblechenko - 27 Apr 2007 19:35 GMT
Outlook cannot see any changes made with Extended MAPI until you completely
dereference and reopen the item.
For some reason Outlook refereshes it internal cache of recipients when you
add a user property (you can immediately delete) it after you add a
recipient but before you display it.
safeItem.Recipients.Add("xxx@zzz.zz");
safeItem.Recipients.ResolveAll();
prop = mailItem.UserProperties.Add( "test", 1 );
prop.Value = "test";
prop.Delete();
mailItem.Subject = "Mail Created";
mailItem.Save();
mailItem.Display(false);
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
> Hi,
> I have a situation where I want to modify an existing item in Outlook,
[quoted text clipped - 90 lines]
>
> Bjorn Tore
Sue Mosher [MVP-Outlook] - 27 Apr 2007 20:19 GMT
Very useful. How on earth did you ever figure that out?

Signature
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
> Outlook cannot see any changes made with Extended MAPI until you completely
> dereference and reopen the item.
[quoted text clipped - 110 lines]
>>
>> Bjorn Tore
Dmitry Streblechenko - 27 Apr 2007 21:07 GMT
The usual head scratching "why does this work in one place but not in
another?" :-)
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Very useful. How on earth did you ever figure that out?

Signature
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
> Outlook cannot see any changes made with Extended MAPI until you
> completely
[quoted text clipped - 114 lines]
>>
>> Bjorn Tore