Programmatically redirecting email. Outlook 2003 Add-in, C#

A

AndersL

I am creating an Outlook 2003 add-in using C# and VSTO second edition. I have
created a CommandBarButton, and want to redirect an email to a given email
address when the button is clicked. It is of importance that the original
subject, content and sender/recievers are kept.

I have the button click event up and running, and I have also extracted the
selected MailItem.

1) Is there framework support in the Outlook OM for redirecting a MailItem
to a given email account, given my criterias above? If there is no direct
support for this, does anyone know a workaround? Code examples are much
appreciated.

2) When the mail message is redirected, I would like to mark the original
message somehow, so the user easily can see that the button has been clicked.
I was thinking to set a custom flag, but that could interfere routines for
the users that use the normal flagging functionality. Any ideas on how to
solve this? Code examples?

3) I also need to prevent that the same email is redirected again by
deactivating the button. I picture that the event handler checks the
"redirected" flag of the message. Does anyone know what event to handle to
catch a change in selection?

Thanks in advance!

Regards,
Anders
 
K

Ken Slovak - [MVP - Outlook]

I'm not quite sure what you mean by redirect in this case.

If you want to send a copy of the message to some email address just take
the copy and clear the Recipients collection and add your own Recipient
object, resolve it and send it.

You can add a UserProperty to the UserProperties collection of any item.
That could be a Boolean in this case that is set true when your redirection
is done.

A code sample for using item.Recipients.Add is in the Object Browser Help,
as is a sample for using UserProperties.Add.

When an item is opened it's opened in an Inspector. You can handle the
NewInspector event of the Inspectors collection and use that to set up your
button initialization. Actually, the button creation should be in the first
Activate event of that Inspector, before that the CommandBars collection and
other attributes of the Inspector and Inspector.CurrentItem may not be
valid.

In the code where you create your button just check for the UserProperty you
created and if it's true set your button properties to .Enabled = false if
you want it there but grayed out, or .Visible = false if you don't want it
shown at all.

There are a number of VSTO samples and C# samples at www.outlookcode.com.
 
A

AndersL

Thank you for your response, Ken.

By redirect, I mean that the email is "bounced" as it is to a given email
address, without changing the sender, recipient, datestamp, subject or body.

To exemplify: I recieve a message. The reciever is "(e-mail address removed)", and the
sender is "(e-mail address removed)". I want to bounce this email to a different
account (e.g. "(e-mail address removed)"), and still keep the original
receiver ([email protected]) and sender ([email protected]). This will make the
message appear as it never has been in my inbox.

Any ideas on how to do this?

Regarding the "flagging" of emails: I mean the selected message in the
Explorer view, not the Inspector. So I guess my question is: What event is
triggered when a user selects a new message for preview in the Explorer? I
was thinking to activate/deactivate the button in that event handler.

Regarding the UserProperties - I think that will solve the issue behind the
scenes, but not visually. Do you have any ideas on how to somehow mark a
message, without using the default flag functionality? I just want the user
to easily notice (in the Explorer) whether the message has been redirected or
not.

Thanks again,

Anders
 
K

Ken Slovak - [MVP - Outlook]

In that case if you aren't really sending an item but want to move it
somewhere I'd use the item.Move method. Before the move you can set a flag
on the item or mark it in some other way such as a category.

If you forward or send an item it will definitely have new properties for
sender and recipients and receive time, any Internet headers will be gone if
this is an internal email and other things will change too.

You might want to look at www.ivasoft.com, as I recall Victor has some
Extended MAPI code there as an addin or sink of some sort that does
redirections, if it does what you want that's a lot better than reinventing
the wheel.
 

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