How to Use the Dundas Mailer Control
Overview | Properties | Methods
The Dundas Mailer Control is a free fully commercial email control which allows you to send both html and text-based emails as well as post articles to news groups. It is used in conjunction with the Dundas Upload Control when dealing with uploaded files, html embedded objects and file attachments.
Two methods are used for sending an email: QuickSend and SendMail. Refer to the sections below for a detailed explanation on how to use the Mailer control with either of these two methods. To post articles to news groups you can utilize the PostArticle method. See Tutorial 3: Posting to a NewsGroup for further details.
Refer to the section below for details on how to use the Mailer and Upload controls together. You can also examine Tutorial 1: Sending an Email with an Attachment or Tutorial 2: Sending an Html Email with an Embedded Image for example source of this.
NOTE: All sending methods utilize the SMTPRelayServers and DNSServers collections. To maximize the speed of the mail operation populate these collections before sending the email message.
Using QuickSend
Create an instance of the Mailer control. The ProgID of the control is "Dundas.Mailer".
Optionally set properties (including collections) used by the QuickSend method. Unlike SendMail (which incorporates all of the control's functionality) QuickSend only utilizes some of the control's properties and collections (all of which are optional). See QuickSend for a listing of these properties.
Call QuickSend to send an email. Notice that this method's arguments are used to set any required message headers.
Error trap for the success/failure of the operation by using an On Error Resume Next statement and examine VBScript's Err object (Err.Number will be a non-zero value if an error occurred) immediately following the function call.
- Destroy the instance of the Mailer control.
Advantage
- Lets you send an email with a minimal amount of coding.
Using SendMail
Create an instance of the Mailer control. The ProgID of the control is "Dundas.Mailer".
Unlike the QuickSend method SendMail does not use function arguments at all. It relies on various properties and collections to set message headers and other message elements (e.g. Body property, SMTPRelayServers collection, TOs collection, TimeOutConnect property, etc.). For the function call to succeed you MUST specify a destination address by adding an Address object to one of the following collections: TOs, CCs, or BCCs. Use the Add method of the collections to do this.
Once you have specified a destination address set any other properties (collections incuded) that you would like to be used for the mailing operation.
Error trap for the success/failure of the operation by using an On Error Resume Next statement and examine VBScript's Err object (Err.Number will be a non-zero value if an error occurred) immediately following the function call.
- Destroy the instance of the Mailer control.
Advantage - Although more coding is required to send an email compared to QuickSend the SendMail method offers you a tremendous amount of flexibilty and options for the mailing operation. It utilizes ALL properties/collections of the control.
Using the Upload and Mailer Controls
Use the Dundas Upload control to save uploaded files and access form elements. Once you have saved the uploaded files to disk you can then access form elements via the Form collection. You can also iterate through all uploaded files via the Upload control's Files collection, which stores UploadedFile objects.
If you are just sending an attachment with the email then add the uploaded file to the Mailer control's Attachments collection. Use the UploadedFile object's Path property as the FileName argument of the Attachments.Add method call. Then call the SendMail method to send the email with the attachment.
To embed uploaded files into an html email loop through the Files collection of the Upload control and add the UploadedFile objects 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.
There are four tutorials which illustrate the various send message operations:
QuickStart (Illustrates how to send an email with a minimum of code).