How do I modify the message body displayed in the email window?

  • Thread starter Thread starter Steffen Heinzl
  • Start date Start date
S

Steffen Heinzl

Hi!

I'm writing an Outlook add-in with VSTO in C#.
Up to now, I used the shortcutBar example (from the MSDN) which creates
a few buttons. By clicking on a button named New Mail, the normal window
appears, in which the Outlook user can write his mail.
Then I added an AttachmentAddEventHandler, which reacts whenever an
Attachment is added to the mail. The function handling the event
receives an Attachment object. By calling attachment.Parent, I get the
email to which the attachment was added.
Now I can modify the body of the mail. The modification works for the
mail object, but is not reflected to the form where the body of the
Email is shown.

Does anybody know how to update the window or at least how to get a
reference to it?

Yours,
Steffen
 
The window you can get a reference to from your item you get from
Attachment.Parent. It would be Item.GetInspector to get an Inspector object.
You can also trap the NewInspector event of the Inspectors collection to get
a reference to the Inspector. ActiveInspector is probably also useful, it's
the active window so would most likely be the window you want.

However, changes you make in code won't show up unless you save the item and
even then may take a while due to latency.
 
Ken said:
The window you can get a reference to from your item you get from
Attachment.Parent. It would be Item.GetInspector to get an Inspector
object. You can also trap the NewInspector event of the Inspectors
collection to get a reference to the Inspector. ActiveInspector is
probably also useful, it's the active window so would most likely be the
window you want.

However, changes you make in code won't show up unless you save the item
and even then may take a while due to latency.

Thanks!

By the method GetInspector, I can get an Inspector obect. But what can I
do with the inspector object? I do not seem to find an attribute or
function that can do something for me.

If I may ask another (more important) question: I want to add a text for
each attachment attached when the send button is clicked. But if I do
something like...

Outlook.MailItem newMail =
(Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.ItemEvents_10_Event temp = (Outlook.ItemEvents_10_Event)newMail;
temp.Send += new Outlook.ItemEvents_10_SendEventHandler(MySendHandler);
temp.AttachmentAdd += new
Outlook.ItemEvents_10_AttachmentAddEventHandler(MyAttachmentHandler);

.... MySendHandler is never called, when I click the send button or
actually send the mail. But if I add an Attachment MyAttachmentHandler
is called.

Yours,
Steffen
 
You asked how to get the window for the item, the Inspector is the window
for the item.

Inspector.CurrentItem is the item in the window, and getting that as a mail
item gives you access to Body and other properties. If you already have the
mail item you don't need the Inspector most likely.

I'd guess for your other problem that the event handler is out of scope.
Normally one would use some form of Inspector wrapper class to wrap each
Inspector that's opened and in that class would live the event handlers for
the Inspector and the item in it. The wrapper class is then kept alive by
adding it to a collection or SortedList or something else that prevents the
garbage collector from removing it.

There's an Inspector wrapper in C# that you might want to look at, it's at
http://www.outlookcode.com/codedetail.aspx?id=797
 
Ken said:
You asked how to get the window for the item, the Inspector is the
window for the item.

Inspector.CurrentItem is the item in the window, and getting that as a
mail item gives you access to Body and other properties. If you already
have the mail item you don't need the Inspector most likely.

I'd guess for your other problem that the event handler is out of scope.
Normally one would use some form of Inspector wrapper class to wrap each
Inspector that's opened and in that class would live the event handlers
for the Inspector and the item in it. The wrapper class is then kept
alive by adding it to a collection or SortedList or something else that
prevents the garbage collector from removing it.

There's an Inspector wrapper in C# that you might want to look at, it's
at http://www.outlookcode.com/codedetail.aspx?id=797

Thank you very much! Now it works!
 
Back
Top