views:

124

answers:

1

I am creating an outlook add in which needs to make modifications on the TO and CC fields before sending the message. I tried editing the TO property of the MailItem object but when I edit it, the mail doesn't get sent, it gets stuck in the Outbox. I also looked at the Recipients collection but it's read only so not of any use. Is there any mapping being maintained by Outlook between TO and Recipients collection which fails when I edit TO property?

What is the ideal way to make these changes and still have the mail be delivered properly?

A: 

Use yourMailItem.Recipients.Add("[email protected]") to add recipients.
To set them as CC set the recipient type to olCC (e.g. Recipients.Item(1).Type = olCC).

Georg Fritzsche
I don't want to "add" new recipients, I want to modify the existing ones which I cannot do since the Recipients collection is ReadOnly
Sanket
You still can "Remove(index)", "set r = Recipients.Add("[email protected]")", "r.Type = olCC", "r.Resolve()"
Georg Fritzsche
... Ideally you'd switch to MAPI (or Redemption), but as MAPI is time consuming i'd try to avoid it.
Georg Fritzsche
Thanks gf, it worked for me.Basically, the reason it was erroring out earlier was because the index for Recipients collection seems to start at 1 and not 0 so I was always getting index out of bounds :-)
Sanket
Been there, done that ;) Don't know who had that strange idea...
Georg Fritzsche