C# Add-in that adds a TO, CC, or BCC to a MailItem

R

rchf

His one supposed to put additional TO/CC/BCC recipients on a MailItem using
C# in VSTO?

I would really appreciate your ideas/suggestions.

Here is the very short source code that was supposed to add the new CC
address....

void applicationObject_ItemSend(object item, ref bool cancel)
{
Outlook.MailItem myItem = item as Outlook.MailItem;

if( myItem != null)
{
myItem.CC = "(e-mail address removed)";
}
}

As I say this code results in the user-created outbound email being sent to
the user-entered email address and shows an attempt to send to the additional
new address "'(e-mail address removed)'"@myhost.com

Apparently Outlook is default-appending the domain name of my IMAP host
provider (myhost.com), from where I get/send my email. I checked and this is
NOT happening on the server-side. Why not just accept the BCC I provide and
why does Outlook append the host's email address?

Thanks,
Richard
 
K

Ken Slovak - [MVP - Outlook]

Outlook normally does not append anything to what you add unless something
is telling it to do so or something else is doing it.

I almost never use direct setting of the To, Cc or Bcc properties. I use the
Recipients collection and its Add method to add a one-off recipient using
the SMTP email address, followed by a call to resolve the new Recipient
address. I set the Type of the Recipient to whatever I want: olTo, olCC or
olBCC.
 
R

rchf

Hi Ken,

Thanks for your suggestion. Doesn't manipulation of the Recipients
collection:
1. trigger a security alert even with C#/VSTO?
and
2. require the temporary address be in the Address Book so it can be
Recipient.Resolve'd ?

I am new so I don't know and would like your thoughts on that as well as the
following...

I have found something that looks like the answer to my original question
and I -might- have found a bug in Outlook.

If I my "default" Email Account in Outlook is IMAP I get a separate folder
hierarchy of "myIMAPhost.com"->Inbox. All inbound personal email avoids
"Personal Folders"->Inbox and goes to "myIMAPhost.com"->Inbox; that is not
the bug.

The bug appears when the -outbound- email departs through this IMAP account.
If I use C#/VSTO to set MailItem.To (or .CC or .BCC) =
"(e-mail address removed)" Outlook then alters the IMAP outbound email to
have the address "'(e-mail address removed)'"@myIMAPhost.com

This odd behavior does NOT happen if my mail transport agent (mail server)
uses POP3 instead of IMAP to communicate with Outlook.

QUESTION: Is this a bug or some kind of intentional differentiation between
handling of outbound email addresses when using IMAP versus POP3 email in
Outlook?

I assume its somehow my mistake but it sure looks odd.

Thanks, Richard
 
K

Ken Slovak - [MVP - Outlook]

The security would depend on the version of Outlook, for Outlook 2007 you
have no problems. For Outlook 2003 with a VSTO addin you would get the
security unless you use a safe wrapper like Redemption
(www.dimastr.com/redemption).

I can't answer about IMAP, I never use it. It's totally buggy even in
Outlook 2007.

You can resolve a one-off recipient, all that's checking for is a properly
formed email address. It does not have to be in an address book, it can be
just "(e-mail address removed)" or anything.
 
R

rchf

Hi Ken,

It really helps to know I should give up on IMAP. That is a huge help. Is
there a page somewhere listing the known bugs in Outlook 2003?

That would save heaps of time for everyone especially If I could add a new
one.

Best,
Richard
 

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