# MTEmail

This object provides methods to send an e-mail message via the MS-CDONTS email object. The e-mail can be based on an XML format template. Support is provided for variable value substitution in the Message Body and the Message Subject.

Each of the following can be set in the template or defined programmatically: To, From, CC, BCC, Subject, Priority, Message Format (MIME, text), Message Body, Format (HTML, plain), Message Body.

This object inherently supports UNICODE.

## Program ID

Email.MTEmail.1

## MTEmail Methods

AddParam | Substitute a value for a variable in Subject and Body.
AttachFile | Attach a file to the e-mail.
AttachURL | Attach HTML.
init | Initialize the e-mail generator (EmailMessage) object.
LoadTemplate | Load the defined XML template and parse.
Send | Send the e-mail message.

## MTEmail Properties

TemplateFileName | Set the name of the template file.
TemplateLanguage | Choose the template language to use.
TemplateName | Set the name of the template (contained within the template file).

## Example

Example to be provided in a future release of this online help system.

# Method Detail

## AddParam

Replace all occurrences of 'Name' with 'Value' in the message subject and body.

### Visual Basic Syntax

Sub AddParam(Name As String, Value As String)

### C++ Syntax

HRESULT AddParam([in] BSTR Name, [in] BSTR Value);

### Arguments

Name

Variable Name to replace.

Value

Value to replace 'Name' with.

### Return Value

S_OK

### Errors Raised

Returns any COM errors that occur.

## AttachFile

Attachs a file to the e-mail message.

### Visual Basic Syntax

Sub AttachFile(apfilename As String)

### C++ Syntax

HRESULT AttachFile([in] BSTR apfilename);

### Arguments

apFilename

The path of the file to attach.

### Return Value

S_OK

### Errors Raised

Returns any COM errors that occur.

## AttachURL

Attaches a URL from a specified location to the e-mail.

STDMETHODIMP CMTEmail::AttachURL(BSTR apSource, BSTR apContentLocation)

### Visual Basic Syntax

Sub AttachURL(apSource As String, apContentLocation As String)

### C++ Syntax

HRESULT AttachURL([in] BSTR apSource, BSTR apContentLocation);

### Arguments

apSource

The source URL of the attachment.

apContentLocation

Equivalent of the base URL for the URL source.

### Return Value

S_OK

### Errors Raised

Returns any COM errors that occur.

## init

Initializes the E-mail Generator with an EmailMessage Object. A CDONTS mail object is created.

The EmailMessage object contains the properties for the e-mail message. Create the object and pass it to this method. The properties of the EmailMessage object can be modified at any time, but may be overwritten when the MTEmail object loads the template.

### Visual Basic Syntax

Sub init(apEmailMessage As IMTEmailMessage)

### C++ Syntax

HRESULT init([in] IMTEmailMessage * apEmailMessage);

### Arguments

apEmailMessage

A pointer to an EmailMessage object.

### Return Value

S_OK

### Errors Raised

E_FAIL - Unable to create a New Mail Object.

Also returns any COM errors that occur.

## LoadTemplate

Loads the language-specific template from the specified file and populates the EmailMessage object based on the fields defined in the template.

### Visual Basic Syntax

Sub LoadTemplate()

### C++ Syntax

HRESULT LoadTemplate();

### Return Value

S_OK

### Errors Raised

E_FAIL: Check the description for the actual error. It will be one of the following:

E-mail Generator has not been initialized.

A valid template was not specified.

Unable to create an instance of a PropSet object.

The specified language could not be found in the template.

A COM error occurred.

## Send

This function populates the properties of the CDONTS mail object then calls the CDONTS object Send method to send the e-mail.

Additionally, a check is made to ensure that a recipient for the message has been specified.

### Visual Basic Syntax

Sub Send()

### C++ Syntax

HRESULT Send();

### Return Value

S_OK

### Errors Raised

E_FAIL - if no recipient specified OR if the CDONTS send fails.

Also returns any COM errors that occur.

# Property Detail

## TemplateFileName

Sets the path of the e-mail template.

### Visual Basic Syntax

Property TemplateFileName (newVal As String)

### C++ Syntax

HRESULT TemplateFileName([in] BSTR newVal);

### Arguments

newVal

The path of the e-mail template file.

### Return Value

S_OK

### Errors Raised

Returns any COM errors that occur.

## TemplateLanguage

Sets the language to the template to use (Contained in the template).

### Visual Basic Syntax

Property TemplateLanguage (newVal As String)

### C++ Syntax

HRESULT TemplateLanguage([in] BSTR newVal);

### Arguments

newVal

Language of the template.

### Return Value

S_OK

### Errors Raised

Returns any COM errors that occur.

## put_TemplateName

Sets the name of the template to use (this template is contained in the template file.

### Visual Basic Syntax

Property TemplateName (newVal As String)

### C++ Syntax

HRESULT TemplateName([in] BSTR newVal);

### Arguments

newVal

Name of the template.

### Return Value

S_OK

### Errors Raised

Returns any COM errors that occur.