Add Method (HtmlEmbeddedObjs collection)

Dundas

Add Method (HtmlEmbeddedObjs collection)

Adds an HtmlEmbeddedObj object to the HtmlEmbeddedObjs collection.

Syntax

HtmlEmbeddedObjsCollection.Add (FileName as string, ContentID as string, [ContentName as string, CustomHeaders as string])

The Add method syntax has the following parts:

Part

Description

FileName

The filename of the object to be embedded.

ContentID

A unique ID which is used to identify each embedded object.

ContentName

The name which will be displayed in the email. If this is not set then the FileName will be displayed.

CustomHeaders

Any custom header.

  Remarks

Use this method to add an HtmlEmbeddedObj object to the HtmlEmbeddedObjs collection. To remove an object use the Remove method. To remove all objects from the collection call the Clear method.

Objects which can be embedded are graphics files, audio files, etc.

MAKE SURE that the values you supply for the ContentID argument are unique. This ContentID is referenced within html tags with "cid:uniquenumber" (see the sample source code below for an example of this). It is also important to use lower-case when specifying "cid". Microsoft's Outlook will not embed objects if you use "CID".

Use the Dundas Upload control to allow the user to specify objects to be embedded in the email. The Upload control exposes a Files collection which consists of UploadedFile objects which can then be used as the embedded objects. To embed the uploaded files loop through the Files collection and add them to the HtmlEmbeddedObjs collection, and then embed the object by wrapping the appropriate html tags around the object in the Mailer control's HtmlBody property. You can use the UploadedFile object's TagName property to determine which file input box the object originated from, and you can also use VBScripts's InStr method in conjunction with the UploadedFile objects ContentType property to determine the type of the object. This lets you make sure that an object is not embedded into the html body of the email with the wrong tags around it (see the code sample below). You can also refer to Tutorial 2: Sending an Html Email with an Embedded Image for sample source code which demonstrates using the Upload control in conjunction with the Mailer control to embed objects into an email.

Please note that it is up to you to wrap the appropriate tags around the embedded objects. This lets you control where in the email the objects will appear. The cid (content ID) is used within the html tags to identify which object in the HtmlEmbeddedObjs collection is to be embedded (see the example source code below).

See Also: HtmlEmbeddedObjs Collection | Clear Method | Count Property | Item Method | Remove Method

Example

'This small code snippet assumes that there is an input element of the File type called
' txtBGSound which lets the user upload a file to the server (to be used for the background

' sound of the html-based email). We check to see if a file was uploaded from this

' particular file input box and then we check the ContentType property of the uploaded

' file to make sure that the user uploaded a valid audio file.

' NOTE: it is assumed here that
objUpload.Save has already been called.

'initialize the HtmlBody property
objEmail.HtmlBody = "<html><body>"

'loop through all files uploaded by user
for
i = 0 to objUpload.Files.Count - 1

'check to see if a file was uploaded using a file input box named "txtBGSound"
if
(objUpload.Files(i).TagName = "txtBGSound") then

'now make sure that the user actually uploaded a valid audio file
if
(InStr(1,objUpload.Files(i).ContentType,"audio")) then

'now add the object to the HtmlEmbeddedObjs collection, and then embed
' the object into the HtmlBody property, wrapping the appropriate tags

' around it. Note that we are setting the ContentName argument of the

' HtmlEmbeddedObj object to the OriginalPath property of the UploadedFile

' object (e.g. c:\MyPic.jpg). Then the resulting name of the object in the

' email will not be preceded with a guid (all uploaded files will be saved

' to disk with a guid as the first part of their filename).

objEmail.HTMLEmbeddedObjs.Add objUpload.Files(i).Path,1,objUpload.Files(i).OriginalPath
objEmail.HTMLBody = objEmail.HTMLBody & "<BGSound src=cid:1></BGSound>"

end if

end if

next

'now finish setting the HtmlBody property
objEmail.HtmlBody = objEmail.HtmlBody & "</body></html>"