BuildersPlanet.comBuildersPlanet Home Page
Host Your Site Here
Marketplace Job Bank Buy/Sell Community News Services
 HOME  >  Services > Web Hosting > Support > ASPEmail Instant Feedback

AspEmail 4.2 Manual

What is AspEmail 4.2

AspEmail 4.2 is an active server component for sending email messages using an external SMTP server in an ASP or VB environment. AspEmail 4.2 supports multiple recipients, multiple CC, multiple Bcc, multiple file attachments, HTML format, embedded images, and non-US ASCII character sets. AspEmail 4.2 is free except for the image embedding functionality, Quoted-Printable encoding support and message queuing described below.

A free copy of AspEmail can be downloaded from www.aspemail.com/download.html.

Changing from AspMail to AspEmail 

It is extremely simple to change your ASP or VB script from using AspEmail in the direct sending mode to EmailAgent-assisted queue mode. All you need to do is replace all the Mail.Send calls by Mail.SendToQueue. For example:

** Note from BP Tech Support: Your mail host should be "mail.yourdomain.com" or "mail.yourdomain.net", etc., as applicable. **

<%
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "mail.mydomain.com"
Mail.From = "sales@mycompany.com"
Mail.FromName = "Sales Department"
Mail.AddAddress "jsmith@company1.com", "John Smith"
Mail.Subject = "Sales Receipt"
Mail.Body = "Dear John:" & chr(13) & chr(10) & "Thank you for your business."
On Error Resume Next
Mail.SendToQueue
If Err <> 0 Then
    Response.Write "An error occurred: " & Err.Description
End If
%>

When the SendToQueue method is called, a message is not sent directly to the SMTP server for delivery. Instead, it is packaged into a file with the extension .stg and placed into the message queue.

>

Using AspEmail

To use AspEmail in an ASP environment, you must create an instance of the AspEmail object in your ASP script as follows:

<%
...
Set Mail = Server.CreateObject("Persits.MailSender")
...
%>

To use AspEmail in a VB environment, open a VB project, go to Project/References... and check the box next to Persits Software AspEmail 4.2. Declare an AspEmail object variable as follows:

Dim Mail As MailSender

Create an instance of the AspEmail object as follows:

Set Mail = New MailSender

To send email messages, AspEmail "talks" to an SMTP server. You must specify the SMTP host address and, optionally, port number as follows:

** Note from BP Tech Support: Your mail host should be "mail.yourdomain.com" or "mail.yourdomain.net", etc., as applicable. **

Mail.Host = "mail.mydomain.com"
Mail.Port = 25 ' Optional. Port is 25 by default

You must also specify the sender's email address and, optionally, name as follows:

Mail.From = "sales@mycompany.com"
Mail.FromName = "Sales Department" ' Optional

To add the message recipients, CCs, BCCs, and Reply-To's, use the AddAddress, AddCC, AddBcc and AddReplyTo methods, respectively. These methods accept two parameters: the email address and, optionally, name. Notice that you must not use an '=' sign to pass values to the methods. For example, < /FONT>

Mail.AddAddress "jsmith@company1.com", "John Smith"
Mail.AddCC "bjohnson@company2.com" ' Name is optional

Use the Subject and Body properties to specify the message subject and body text, respectively. A body can be in a text or HTML format. In the latter case, you must also set the IsHTML property to True. For example,

Mail.Subject = "Sales Receipt"
Mail.Body = "Dear John:" & chr(13) & chr(10) & "Thank you for your business. Here is your receipt."

or

Mail.Subject = "Sales Receipt"
Mail.Body="<HTML><BODY BGCOLOR=#0000FF>DearJohn:....</BODY></HTML>"
Mail.IsHTML = True

To send a file attachment with the message, use the AddAttachment method. It accepts the full path to the file being attached. Call this method as many times as you have attachments. Notice that you must not use the '=' sign to pass a value to the method: < /FONT>

** Note from BP Tech Support: the path below is correct for you. Make sure that you put your attachment in this directory first. Dont' forget that "yourdomaincom" may be "yourdomainnet", etc., as applicable. **

Mail.AddAttachment "d:\html\users\yourdomaincom\filename.doc"

To send a message, call the Send method. The method throws exceptions in case of an error. You may choose to handle them by using the On Error Resume Next statement, as follows:

On Error Resume Next
Mail.Send
If Err <> 0 Then
    Response.Write "An error occurred: " & Err.Description
End If

>


S/MIME-based Encryption and Digital Signature Support

Starting with Build 4.0.0.3, AspEmail is capable of generating encrypted and/or signed mail in the industry-standard S/MIME format. To send secure mail, AspEmail must be used in conjunction with the AspEncrypt cryptographic component from Persits Software, Inc. For more information on how to send secure mail using the AspEmail and AspEncrypt components, and to download your free trial copy of AspEncrypt, visit the web site http://www.aspencrypt.com/.

>

Premium Feature: Support for Message Queuing

** Note from BP Tech Support - We have the EmailAgent installed. **

AspEmail 4.2 has a new method, SendToQueue, which does not attempt to send a message directly to the SMTP server. Instead, the message is placed in a queue from where it is later retrieved and sent out by the EmailAgent NT service, a background process. Your mail-sending ASP script no longer has to wait until a message is sent, which means a better client-response time.

>

Premium Feature: Sending Messages with Embedded Images and Sounds

AspEmail can send email messages with embedded images. The following example uses the file margin.gif (included with the component) as the background image for a message:

** Note from BP Tech Support: the paths below are correct for you. Make sure that you put your attachment in this directory first. Don't forget that "yourdomaincom" may be "yourdomainnet", etc., as applicable. **

...
Mail.Body="<HTML><BODYBACKGROUND=""cid:My-Background-Image"">...</BODY></HTML>"
Mail.AddEmbeddedImage "d:\html\users\yourdomaincom\filename.gif", "My-Background-Image"

The method AddEmbeddedImage takes two parameters: the full path to an image file and a Content ID which is simply a string without spaces which your body HTML references as follows:

"cid:<ContentID>"

In the example above we use the Content ID "My-Background-Image" which is referenced by the BACKGROUND attribute of a <BODY> tag. We can use the same technique to embed an image inside the message body using an <IMG> tag:

Mail.Body= "<HTML>....<IMGSRC=""cid:My-Company-Logo"">...</HTML>"
Mail.AddEmbeddedImage "d:\html\users\yourdomaincom\filename.gif", "My-Company-Logo"

In a similar manner, you can embed a sound file in your message using the <BGSOUND> tag, for example:

Mail.Body ="<HTML><BGSOUND=""cid:My-Sound""></BGSOUND>...</HTML>"
Mail.AddEmbeddedImage "d:\html\users\yourdomaincom\filename.wav", "My-Sound"

Note: Content-IDs are case-sensitive. Make sure the values specified by "cid:..." and AddEmbeddedImage fully match.

To make your script more readable, you may choose to place your message body in a separate file and import it into the Body property using the method AppendBodyFromFile which accepts the full path to a text ot HTML file containing the message body. For example, your HTML file may look like this:
  <!-- File messagebody.html-->
<HTML>
<HEAD>
<STYLE>BODY {
 COLOR: #427d64; FONT-FAMILY: "Arial"; FONT-SIZE: 12pt; MARGIN-LEFT: 8em
}
</STYLE>
</HEAD>

<BODY BACKGROUND="cid:My-Background-Image">
<H2>Thank you for Shopping At Our Online Store!</H2>

....

</BODY>
</HTML>

To use this file as a message body, use the following code:

Mail.AppendBodyFromFile "d:\html\users\yourdomaincom\filename.html"
Mail.AddEmbeddedImage "d:\html\users\yourdomaincom\filename.gif", "My-Background-Image"

The AppendBodyFromFile method can be used instead of, or in conjunction with, the Body property.

>

Premium Feature: Support for Alphabets Other Than US-ASCII

AspEmail is capable of sending messages in alphabets other than US-ASCII by supporting the "Quoted-Printable" format. This format is described in RFC-2045. The idea of the format is that characters less than 33 and greater than 126 are represented by an "=" followed by a two digit hexadecimal representation of the character's value. For example, the decimal value 12 (US-ASCII form feed) is represented by "=0C", and the decimal value 61 (US-ASCII "=") can be represented by "=3D".

AspEmail encodes the message body in the Quoted-Printable format automatically if the ContentTransferEncoding property is set to "quoted-printable". You may also set the CharSet property to the appropriate character set.

The following code snippet sends a message in Russian in the KOI8 standard from a text file (not shown here):
...
Mail.ContentTransferEncoding = "quoted-printable"
Mail.Charset = "koi8-r"
Mail.AppendBodyFromFile "d:\html\users\yourdomaincom\filename.txt"
Mail.Send

>


Sample ASP Application

** Note from BP Tech Support: These files are available at ... **

AspEmail is shipped with a sample ASP application that allows you to create and send email messages with attachments over the Web. The application consists of the following files:

global.asa (collection object creation)
SendMail.asp (main Email interface page)
Attachments.asp (attachment handling page)
UploadScript.asp (upload script which uses AspUpload).

To upload file attachments from a client machine to the server where the script is running, the application uses a trial version of AspUpload, a powerful file upload component from Persits Software. The file AspUpload.dll is shipped with AspEmail and must be registered on your system for the sample application to function. For complete documentation on the AspUpload component, or to purchase AspUpload, visit http://www.aspupload.com/.

>

Object Reference

AspEmail Properties

Property and Type Comments
Host As String Required. The internet address of a SMTP host to be used to send messages.
Port As Integer The SMTP port number. 25 by default.
From As String Required. The sender's email address.
FromName As String The sender's name.
Subject As String Message subject.
Body As String Message body. Can be in a text or HTML format. In the latter case, the IsHTML property must be set to True.
IsHTML As Boolean False by default. If set to True, AspEmail will set the Content-Type of the message body to text/html. 
Priority As Integer Message priority. Valid values are 1 (high), 3 (normal) and 5 (low). 0 by default which means priority is not specified.
Helo As String "AspEmail" by default. This string is sent with the HELO command when an SMTP session begins. Used by an SMTP client to identify its domain name to the SMTP server.
ContentTransferEncoding As String "7bit" by default. Specifies the Content-Transfer-Encoding MIME header for the message body. Other valid values include "8bit" and "quoted-printable". If you set this property to "quoted-printable" AspEmail will automatically convert the message body to the Quoted-Printable format as specified in RFC-2045.  This is a premium feature.
CharSet As String "ISO-8859-1" by default. Specifies the charset component of the Content-Type MIME header. This is a premium feature.
Timestamp  As Date Used for deferred message processing. Specifies when the message is to be sent out by EmailAgent. This property is only used with the SendToQueue method and ignored by the Send method. For more information, see the EmailAgent manual at http://www.aspemail.com/, section "Deferred Message Processing."
Expires As Date (read-only) Returns the expiration date of the component's premium features. Returns 9/9/9999 if a valid registration key is installed. Returns 0 (displayed as "12:00 AM") if expiration value in the registry is corrupt or missing.

 

AspEmail Methods

Method Name Arguments Comments
AddAddress Email As String
Optional Name = ""
Adds an email address and optionally the corresponding full name to the letter's To: list. 
AddCC Email As String
Optional Name = ""
Adds an email address and optionally the corresponding full name to the letter's Cc: list.
AddBcc Email As String
Optional Name = ""
Adds an email address and optionally the corresponding full name to the letter's Bcc: list.
AddReplyTo Email As String
Optional Name = ""
Adds an email address and optionally the corresponding full name to the letter's Reply-To: list.
AddAttachment Path As String Adds a file to the list of file attachments to be sent with the message.
AddEmbededImage Path As String
ContentID As String
Adds an image file to the list of images embedded in the message body. ContentID is a string without spaces, such as "My-Image", which will be referenced by the body HTML in the following way:

<IMG SRC="cid:My-Image">

or

<BODY BACKGROUND="cid:My-Image">

This is a premium feature.

AppendBodyFromFile Path As String Appends the Body property from a text or HTML file specified by Path. This is a premium feature.
Send N/A Sends the message. Throws exceptions in case of an error. See the section Error Codes below for the list of error codes.
SendToQueue Optional Path = "" Sends a message to the message queue and returns immediately. Requires the EmailAgent service to be running. Path specifies the path to a message queue where the message is to be posted. If Path is omitted, EmailAgent's Message Queue Path configuration parameter in the registry will be used.
SendEncrypted Msg As CryptoMessage Sends an encrypted message. Msg is an object creatable by the AspEncrypt component. See AspEncrypt Web site for more information.
SendSigned Msg As CryptoMessage Sends a digitally signed message. See AspEncrypt Web site for more information.
SendSignedAndEncrypted Msg1 AspCryptoMessage, Msg2 As CryptoMessage Sends a message which is first digitally signed and then encrypted. See AspEncrypt Web site for more information.
Reset N/A Clears all address and attachment lists so that a new message can be sent.
ResetAll N/A Same as Reset plus resets all properties to their respective default values.
LogonUser Domain As String;
UserID As String;
Password As String.
Impersonates the specified user account. If Domain is empty the local computer will be used to validate the UserID/Password. The caller must have the "Act as Part of the Operating System" privilege, otherwise the error "Privilege is not held by client" error will be thrown.

This method is useful when using the SendToQueue method if the message queue is located on another machine and the current user account's credentials are insufficient to place a message in a remote queue.

RevertToSelf N/A Ends impersonation begun by LogonUser.

 

Error Codes  

Error Code Description
1 Winsock initialization failed.
2 gethostbyname failed.
3 Socket creation failed.
4 Connection failed.
5 Sending data failed.
6 Error returned from SMTP server
7 Opening file failed.
8 Not enough memory.
9 Reading from file failed.
10 Host not specified
11 ContentID may not be empty (generated by AddEmbededImage)
12 ContentID must be unique (generated by AddEmbeddedImage)
13 Invalid Priority value (generated by put_Priority)
14 Component is expired or invalid registration key (generated by premium methods and properties only)

Copyright (c) 1999 Persits Software, Inc.
All Rights Reserved

Home|Contact Us|Hosting Terms

© Copyright 1999-2000. BuildersPlanet.com All rights reserved..
By using this site you accept our terms  and privacy policy.
For comments or problems, email Webmaster@buildersplanet.com or call 831-335-0475