Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Programmatically redirecting email. Outlook 2003 Add-in, C#

Geek News

Programmatically redirecting email. Outlook 2003 Add-in, C#
AndersL 2/23/2007 8:03:08 AM
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

Re: Programmatically redirecting email. Outlook 2003 Add-in, C#
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 2/23/2007 3:22:13 PM
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"AndersL" <AndersL[ at ]discussions.microsoft.com> wrote in message
news:73E04FA2-0D3C-480A-B66B-BFA6572701BE[ at ]microsoft.com...
[Quoted Text]
>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
>

Re: Programmatically redirecting email. Outlook 2003 Add-in, C#
AndersL 2/23/2007 4:33:38 PM
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 "me[ at ]domain.com", and the
sender is "sender[ at ]domain.com". I want to bounce this email to a different
account (e.g. "somewhereElse[ at ]domain.com"), and still keep the original
receiver (me[ at ]domain.com) and sender (sender[ at ]domain.com). 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


"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> 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.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "AndersL" <AndersL[ at ]discussions.microsoft.com> wrote in message
> news:73E04FA2-0D3C-480A-B66B-BFA6572701BE[ at ]microsoft.com...
> >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
> >
>
>
Re: Programmatically redirecting email. Outlook 2003 Add-in, C#
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 2/26/2007 4:35:16 PM
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"AndersL" <AndersL[ at ]discussions.microsoft.com> wrote in message
news:C7519745-2D46-4CAC-BB49-878F677D40F0[ at ]microsoft.com...
[Quoted Text]
> 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 "me[ at ]domain.com", and
> the
> sender is "sender[ at ]domain.com". I want to bounce this email to a different
> account (e.g. "somewhereElse[ at ]domain.com"), and still keep the original
> receiver (me[ at ]domain.com) and sender (sender[ at ]domain.com). 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

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