AspEmail 4.5 Manual


What is AspEmail

AspEmail 4.5 is an active server component for sending email messages using an external SMTP server in an ASP environment. AspEmail 4.5 supports multiple recipients, multiple CC, multiple Bcc, multiple file attachments, HTML format and non-US ASCII character sets. 

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 send email messages, AspEmail "talks" to an SMTP server. You must specify the SMTP host address and, optionally, port number as follows:

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

Starting with AspEmail 4.3, you can specify a comma- or semicolon-separated list of SMTP hosts, as follows:

Mail.Host = "mail.yourdomain.com;mail2.yourdomain.com;host.someotherdomain.com"

If the first host on the list is down, AspEmail will automatically attempt to connect to the second host, etc. If none of the specified hosts are working an error exception will be thrown.

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

Mail.From = "sales@yourdomain.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,

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>Dear John:....</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:

Mail.AddAttachment Server.Mappath ("/doc") & "receipt.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

Support for Alphabets Other Than US-ASCII

AspEmail is capable of sending messages in alphabets other than US-ASCII. This format is described in RFC-2045. You may also set the CharSet property to the appropriate character set.

The following code snippet sends a message in Thai in the windows-874:
...
Mail.Charset = "windows-874"
Mail.Subject = "Thai Subject"

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

Mail.Send