Attachments

R

Richard

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!
 
K

Ken Slovak - [MVP - Outlook]

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.
 
R

Richard

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""><HTML><HEAD><META http-equiv=Content-Type
content=""text/html;charset=Diso-8859-1""><META content=""MSHTML
6.00.6000.16608"" name=GENERATOR><STYLE></STYLE></HEAD><BODY
bgColor=#ffffff><DIV><FONT 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.
 
K

Ken Slovak - [MVP - Outlook]

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.
 

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