Using ASPEMAIL to send mails using ASP
Posted by Nexus Support Admin on 31 October 2003 01:35 PM
Nexus recommends that you use ASPEMAIL to send mail on our Windows 2000 Hosting servers instead of CDONTS.
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")

Essential Properties and Methods
In order to send email, AspEmail "talks" to an SMTP server. You must specify the address of your SMTP server via the Host property. The default port number for SMTP services is 25, but if your SMTP server runs on a different port, you must also specify it via the Port property:

Mail.Host = "mail.YOURDOMAIN.COM" ' Required
Mail.Port = 25 ' Optional. Port is 25 by default

For using ASPemail on Nexus' servers, Just specify the Mail.Host as "mail.YOURDOMAIN.COM" where is the domain you have hosted with us. Modifications to the port are not required.

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

Mail.From = "" ' Required
Mail.FromName = "Sales Department" ' Optional

To add 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 "", "John Smith"
Mail.AddCC "" ' 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,

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


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

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
If Err <> 0 Then
Response.Write "An error occurred: " & Err.Description
End If

Code Samples
The following code sample demonstrates a simple email-sending form.

' change to address of your own SMTP server
strHost = "mail.YOURDOMAIN.COM"
If Request("Send") <> "" Then
Set Mail = Server.CreateObject("Persits.MailSender")
' enter valid SMTP host
Mail.Host = strHost

Mail.From = Request("From") ' From address
Mail.FromName = Request("FromName") ' optional
Mail.AddAddress Request("To")

' message subject
Mail.Subject = Request("Subject")
' message body
Mail.Body = Request("Body")
strErr = ""
bSuccess = False
On Error Resume Next ' catch errors
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
bSuccess = True
End If
End If

<% If strErr <> "" Then %>
<h3>Error occurred: <% = strErr %>
<% End If %>
<% If bSuccess Then %>
Success! Message sent to <% = Request("To") %>.
<% End If %>
<TD>Host (change as necessary in script):</TD>
<TD><B><% = strHost %></B></TD>
<TD>From (enter sender's address):</TD>
<TD>FromName (optional, enter sender's name):</TD>
<TD>To: (enter one recipient's address):</TD>

A sample aspemail file with default configurations can be found in the downloads area of our knowledgebase here