Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   Attachments (http://www.outlookbanter.com/add-ins-outlook/72256-attachments.html)

Richard May 19th 08 09:27 PM

Attachments
 
I am new to outlook add-in programming and am having a variety of problems.
Today it's existing attachments. I am trapping the Send event and trying to
process attachments on the message item. In this case a message with
attachments is being forwarded. I find that:
1) if I change the message body property, the attachments are deleted. If I
change the bodyhtml property, the attachments remain.

2) if I add a new attachment, the existing attachments are deleted.

I expected the existing attachments to be retained when I add a new one and
did not expect changing the body property to affect the attachments.

Any help or pointers to documentation discussing these issues would be
appreciated!

Ken Slovak - [MVP - Outlook] May 19th 08 10:09 PM

Attachments
 
Probably the attachments are embedded in the item and by changing Body you
are overwriting the original attachment references in the original html. If
you are preserving the original html when you change HTMLBody that would
explain that.

Show the code where you add a new attachment.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Richard" wrote in message
...
I am new to outlook add-in programming and am having a variety of problems.
Today it's existing attachments. I am trapping the Send event and trying
to
process attachments on the message item. In this case a message with
attachments is being forwarded. I find that:
1) if I change the message body property, the attachments are deleted. If
I
change the bodyhtml property, the attachments remain.

2) if I add a new attachment, the existing attachments are deleted.

I expected the existing attachments to be retained when I add a new one
and
did not expect changing the body property to affect the attachments.

Any help or pointers to documentation discussing these issues would be
appreciated!



Richard May 19th 08 10:56 PM

Attachments
 
Ken,
Thanks for taking this up. In my code, I was setting the bodyhtml and the
body properties to some boiler plate text. Setting the bodyhtml did not
disturb the existing attachments, setting the body made the attachments drop
out of the attachments collection. Im this case, the existing attachments are
images referenced in the body html and if the references are removed, then I
guess it makes sense to remove the images. The images are shown as by value
type, position 0 (hidden). But you would think replacing the bodyhtml would
cause a problem as well. The goal is put the body into it's own attachment
and replace the body with boiler plate. Then when received, the process will
be reversed. Here is a snippet of code:

HtmlHeader = "!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0
Transitional//EN""HTMLHEADMETA http-equiv=Content-Type
content=""text/html;charset=Diso-8859-1""META content=""MSHTML
6.00.6000.16608"" name=GENERATORSTYLE/STYLE/HEADBODY
bgColor=#ffffffDIVFONT face=Arial size=2"""
HtmlHeader = HtmlHeader.TrimEnd("""")
HtmlTrailer = "/FONT/DIV/BODY/HTML"

Select Case MailItem.BodyFormat
Case Outlook.OlEditorType.olEditorText
'AddinExpress.OE.BodyFormats.FormatPlain
My.Computer.FileSystem.WriteAllText(FileName,
MailItem.Body, False)
MailItem.Body = MessageReplacement

Case Outlook.OlEditorType.olEditorHTML
'AddinExpress.OE.BodyFormats.FormatHTML
My.Computer.FileSystem.WriteAllText(FileName,
MailItem.HTMLBody, False)
MailItem.HTMLBody = HtmlHeader +
MessageReplacement.Replace(vbCrLf, "br") + HtmlTrailer
'MailItem.Body = MessageReplacement

I checked the attachments collection before and after the last two
statements above to see that the attachments were being affected by chaning
the body parameter.

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

Probably the attachments are embedded in the item and by changing Body you
are overwriting the original attachment references in the original html. If
you are preserving the original html when you change HTMLBody that would
explain that.

Show the code where you add a new attachment.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Richard" wrote in message
...
I am new to outlook add-in programming and am having a variety of problems.
Today it's existing attachments. I am trapping the Send event and trying
to
process attachments on the message item. In this case a message with
attachments is being forwarded. I find that:
1) if I change the message body property, the attachments are deleted. If
I
change the bodyhtml property, the attachments remain.

2) if I add a new attachment, the existing attachments are deleted.

I expected the existing attachments to be retained when I add a new one
and
did not expect changing the body property to affect the attachments.

Any help or pointers to documentation discussing these issues would be
appreciated!




Ken Slovak - [MVP - Outlook] May 20th 08 02:24 PM

Attachments
 
The only real way to tell what's going on is to capture the existing HTML
code in HTMLBody before you start your changes and after to see what's going
on. Usually if the attachments are embedded images the HTML for them would
start like this:

img style="border: 0px" src=

Then the reference for the image would be either a URL or a cid reference. A
cid reference would indicate an attached image file.

The Position argument is really only effective in RTF messages.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Richard" wrote in message
...
Ken,
Thanks for taking this up. In my code, I was setting the bodyhtml and the
body properties to some boiler plate text. Setting the bodyhtml did not
disturb the existing attachments, setting the body made the attachments
drop
out of the attachments collection. Im this case, the existing attachments
are
images referenced in the body html and if the references are removed, then
I
guess it makes sense to remove the images. The images are shown as by
value
type, position 0 (hidden). But you would think replacing the bodyhtml
would
cause a problem as well. The goal is put the body into it's own attachment
and replace the body with boiler plate. Then when received, the process
will
be reversed. Here is a snippet of code:

HtmlHeader = "!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0
Transitional//EN""HTMLHEADMETA http-equiv=Content-Type
content=""text/html;charset=Diso-8859-1""META content=""MSHTML
6.00.6000.16608"" name=GENERATORSTYLE/STYLE/HEADBODY
bgColor=#ffffffDIVFONT face=Arial size=2"""
HtmlHeader = HtmlHeader.TrimEnd("""")
HtmlTrailer = "/FONT/DIV/BODY/HTML"

Select Case MailItem.BodyFormat
Case Outlook.OlEditorType.olEditorText
'AddinExpress.OE.BodyFormats.FormatPlain
My.Computer.FileSystem.WriteAllText(FileName,
MailItem.Body, False)
MailItem.Body = MessageReplacement

Case Outlook.OlEditorType.olEditorHTML
'AddinExpress.OE.BodyFormats.FormatHTML
My.Computer.FileSystem.WriteAllText(FileName,
MailItem.HTMLBody, False)
MailItem.HTMLBody = HtmlHeader +
MessageReplacement.Replace(vbCrLf, "br") + HtmlTrailer
'MailItem.Body = MessageReplacement

I checked the attachments collection before and after the last two
statements above to see that the attachments were being affected by
chaning
the body parameter.




All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com