Assign To and CC list while using Redemption.dll library

P

paresh

Hi,

I could see that objSafeMailItem.To and objSafeMailItem.CC properties are
read only. Could any one tell me if there is any way to set added or is being
added recipients to To or CC list in below code:

' itm is selected Mail item object
Set objSafeMailItem = CreateObject("Redemption.SafeMailItem")
Set rpl = CreateObject("Redemption.SafeMailItem")
objSafeMailItem.Item = itm
rpl.Item = itm.Forward

' By default all recipients are getting added to To list. I want
some in CC list as well. Is it possible?

rpl.Recipients.Add (objSafeMailItem.Sender.Name)

For Each olkRecipient In objSafeMailItem.Recipients
rpl.Recipients.Add (olkRecipient.Name)
Next

rpl.Recipients.ResolveAll

Thanks,
Paresh
 
K

Ken Slovak - [MVP - Outlook]

It's the same process as when you add a Recipient using the Outlook object
model. Once you get back the SafeRecipient object from the call to
SafeRecipients.Add() you set the Type of the Recipient. You use one of the
OlMailRecipientType enum members: olTo, olCC or olBCC.
 
D

Dmitry Streblechenko

Since only reading of the To property is blocked, SafeMailItem only
implements the read access. Since write access is not blocked, you can use
the original Outlook Object (itm)

Or you can declare objSafeMailItem as a generic Object rather than
Redemption.safeMailItem to force late binding: you won't get the compiler
warning and Redemption will be happy to forward the calls to the properties
and methods that it does not implement to the original object assigned to
the Item property.


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
P

paresh

Dmitry,

I have changed the type of rpl to Object and below did trick. thanks.

rpl.To = objSafeMailItem.To
rpl.CC = objSafeMailItem.CC
rpl.Recipients.ResolveAll

But it is not resolving the recipients now. :-( Any idea?

Thanks,
Paresh
 
P

paresh

Ken, this looks great idea. Could you tell me how could I enum rpl.Recipients
and can set the type?

rpl.Recipients.Add (objSafeMailItem.Sender.Name)

For Each olkRecipient In objSafeMailItem.Recipients
rpl.Recipients.Add (olkRecipient.Name)
Next

??? Enume rpl.Recipients

For Each olkRecipient In rpl.Recipients
?? how to set the type
Next

thanks,
Paresh
 
K

Ken Slovak - [MVP - Outlook]

You can use the For...Each loop you show below or you can get the Count of
the original item's Recipients collection and use a standard For...Next
loop. It's like iterating any collection, not rocket science.

To assign the type is totally simple:

oRecip.Type = OlMailRecipientType.olTo ' or olCC or olBCC
 
P

paresh

Thanks Ken, I did below:

For Each olkRecipient In objSafeMailItem.Recipients
olkRecipient.Type = OlMailRecipientType.olCC
rpl.Recipients.Add (olkRecipient.Name)
Next

Still it is adding it To list only all the recipients. Am I doing anything
wrong?

Thanks,
Paresh
 
K

Ken Slovak - [MVP - Outlook]

You are attempting to change the Type of the original recipients and hoping
they will be that Type when added to a new mail item as recipients, and it
just doesn't work that way.

Any recipient object added to a mail item will be olTo unless you explicitly
set its Type on the new Recipient object.

For Each olkRecipient In objSafeMailItem.Recipients
Set oRecip = rpl.Recipients.Add (olkRecipient.Name)
oRecip.Type = OlMailRecipientType.olCC
Next

You of course would have to declare that oRecip object somewhere prior to
that loop.
 
P

paresh

Thanks Ken, it works absolutely fine. See my below code:

rpl.Recipients.Add (objSafeMailItem.Sender.Name)
For Each olkRecipient In objSafeMailItem.Recipients
Set odRecip = olkRecipient
Set oRecip = rpl.Recipients.Add(olkRecipient.Name)
oRecip.Type = odRecip.Type
Next
rpl.Recipients.ResolveAll

I have only one problem in resolving the email addresses that are outside
our domain. It resolves the our domain address perfectly but it can't if
email address in outside the domain. I think this is happening because I am
using Recipient.Name property. So suppose name="xxx yyy" and oririginal email
id = "(e-mail address removed)" then it keeps "xxx yyy" in the recipients list and
not resoving to original email id.

Could you help me here.

Thanks for being there.
Paresh
 
P

paresh

Ken, I have changes the Recipient.Name property to Recipient.Address and its
works perfect now.

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

The name will only resolve correctly for an entry in your GAL or your
Contacts folder. As you found, the Recipient.Address is more universal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top