AttachURL Method (CDONTS NewMail Object)

The AttachURL method adds an attachment to the message and associates a Uniform Resource Locator (URL) with the attachment.

Syntax

objNewMail.AttachURL(Source, ContentLocation [, ContentBase] [, EncodingMethod] ) 
 
objNewMail
Required. This NewMail object.
Source
Required. IStream object or String. The full path and file name of the resource to be attached to the message, or a pointer to an IStream object containing the file data.
ContentLocation
Required. String. The absolute or relative prefix for the URL that the rendering client can use to reference this attachment.
ContentBase
Optional. String. A base for the URL used to reference this attachment.
EncodingMethod
Optional. Long. The manner of encoding the attachment. The following values are possible:
EncodingMethod setting Value Description
CdoEncodingUUencode 0 The attachment is to be in UUEncode format (default).
CdoEncodingBase64 1 The attachment is to be in base 64 format.

Remarks

You must supply at least the ContentLocation parameter to specify a URL for the attachment. If you also supply the ContentBase parameter, it is combined with the ContentLocation parameter to define the full URL path by which this attachment is to be referenced. For more information on constructing URL paths, see the ContentLocation property.

The default value for the EncodingMethod parameter can change if you set the MailFormat property. If MailFormat is set to CdoMailFormatText, the default value is CdoEncodingUUencode. If MailFormat is set to CdoMailFormatMime, the default value is CdoEncodingBase64. However, if you add an attachment encoded in base 64 format, the value of the MailFormat property is automatically set to CdoMailFormatMime.

Only C/C++ and Java programs can use an IStream object for the Source parameter. They should pass an IUnknown object that returns an IStream interface in response to QueryInterface. Microsoft?Visual Basic?supports the IDispatch interface and not IUnknown, so it cannot use an IStream object.

Example

This code fragment illustrates the preparation and sending of an MHTML (MIME HTML) message and attachment using the AttachURL method:

Dim myMail 
Set myMail = CreateObject("CDONTS.NewMail") 
 
HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL 
HTML = HTML & "<html>" 
HTML = HTML & "<head>" 
HTML = HTML & "<meta http-equiv=""Content-Type""" 
HTML = HTML & "content=""text/html; charset=iso-8859-1"">" 
HTML = HTML & "<meta name=""GENERATOR"" content=""Microsoft FrontPage 2.0"">" 
HTML = HTML & "<title>Exchange CDO Example</title>" 
HTML = HTML & "</head>" 
HTML = HTML & "<body bgcolor=""#FFFFFF"">" 
HTML = HTML & "<p><font size=""6"" face=""Arial Black""><strong>Exchange CDO " 
HTML = HTML & "Sample<img src=CDO.gif>" 
HTML = HTML & "</strong></font></p>" 
HTML = HTML & "<p>CDO for NTS allows an easy way to send mail." 
HTML = HTML & "This example shows how the content can be an HTML page" 
HTML = HTML & "which allows you to send rich text and inline graphics.</p>" 
HTML = HTML & "</body>" 
HTML = HTML & "</html>" 
 
myMail.AttachURL "D:\wwwroot\CDO.gif", "CDO.gif" 
myMail.From = "Example@Microsoft.com" 
myMail.To = "Someone@Microsoft.com" 
myMail.Subject = "Sample Message" 
myMail.BodyFormat = 0 
myMail.MailFormat = 0 
myMail.Body = HTML 
myMail.Send