wodMailbox ActiveX Control - Add Method
      
 

Description

Adds new attachment to the message.


Return Type

A Message object.  Reference to new IMessage object that holds message part created for attachment.


Syntax

object.Add (Filename, [Encoding])



The Add Method syntax has these parts:

Part Description
object An expression evaluating to an object of type Attachments.
Filename Required. A String value. Specifies file on your disk you want to attach.
Encoding Optional. A Variant value. Specifies type of preferred encoding.

Remarks

Once you want to add attachment to the message, you will use this method. It takes file from your disk, and puts it in appropriate place in the message.

Please note that wodMailbox may do significant changes on your message if you use this method. First, it has to determine if message is already multipart. If not, it will create appropriate headers (by default this will be 'Content-type: multipart/mixed'), choose boundary to use for parts separation, create new message part, and add encoded attachment to the message.

Using this scenario, it's easy for you to create new message, with a simple line like this:

maibox.Messages(0).Attachments.Add "myfile.zip"

Don't forget to call Update method to actually write changed message contents back to mailbox!

Since in above sample we didn't specify encoding to use, wodMailbox uses Base64 as default.

What happens to the message file after Add is called? wodMailbox creates temporary file, adds one header 'Content-Transfer-Encoding' with encoding name, and after one empty line just writes encoded data. After that, that part is just inserted using Messages.Add method for adding new message parts. We can do this, because Attachments.Add generates regular mail message with headers, empty line and some body.

As you might have noticed so far, we didn't specify filename in attachment part. Also, we didn't specify any additional data that can be used by mail client to determine where and how to save this file (except for how to decode it). It would be good idea to add this info manually. This is pretty simple, since Add method returns reference to new part that was just created. Adding new headers is easy:

Dim part As Message
Set part = mailbox.Messages(0).Attachments.Add("c:\myfile.zip")
part.Headers.Add "Content-Type", "application/x-zip-compressed"
part.Headers.Add "Content-Disposition", "attachment; filename=""fakefile.zip"""

(for above sample to work your mailbox must contain at least one message)

When Add method is used, file is encoded internally and stored to temporary file. wodMailbox will hold this file opened as long as mailbox is valid and not updated. Once you call Update method, mailbox file is recreated, temporary file is moved to mailbox, and temporary file gets deleted.

For a list of most common mime types, click here.