Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Adding recipients to existing mail Items using Redemption

Geek News

Adding recipients to existing mail Items using Redemption
bjornte[ at ]hotmail.com 4/27/2007 10:02:31 AM
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[ at ]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[ at ]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

Re: Adding recipients to existing mail Items using Redemption
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 4/27/2007 6:35:14 PM
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[ at ]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

<bjornte[ at ]hotmail.com> wrote in message
news:1177668151.428082.188100[ at ]r35g2000prh.googlegroups.com...
[Quoted Text]
> 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[ at ]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[ at ]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
>


Re: Adding recipients to existing mail Items using Redemption
"Sue Mosher [MVP-Outlook]" <suemvp[ at ]outlookcode.com> 4/27/2007 7:19:01 PM
Very useful. How on earth did you ever figure that out?

--
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

"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> wrote in message news:ex5FzpPiHHA.3808[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
> 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[ at ]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
>
> <bjornte[ at ]hotmail.com> wrote in message
> news:1177668151.428082.188100[ at ]r35g2000prh.googlegroups.com...
>> 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[ at ]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[ at ]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
>>
>
>
Re: Adding recipients to existing mail Items using Redemption
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 4/27/2007 8:07:29 PM
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

"Sue Mosher [MVP-Outlook]" <suemvp[ at ]outlookcode.com> wrote in message
news:%23HlztEQiHHA.208[ at ]TK2MSFTNGP05.phx.gbl...
Very useful. How on earth did you ever figure that out?

--
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

"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> wrote in message
news:ex5FzpPiHHA.3808[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
> 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[ at ]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
>
> <bjornte[ at ]hotmail.com> wrote in message
> news:1177668151.428082.188100[ at ]r35g2000prh.googlegroups.com...
>> 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[ at ]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[ at ]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
>>
>
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net