First we need to create the variables that we are going to be using in this script.
<%
'Dimension variables
Dim objJMail 'Holds the JMail Object
Next we need to create an instance of the 'JMail' object on the server.
'Create the e-mail server object
Set objJMail = Server.CreateObject("JMail.SMTPMail")
Once the 'JMail' object has been created on the server we can use various properties and methods of the 'JMail' object to build the email.
First we need to specify the address of the SMTP server you are using to send mail through. You can specify more than one SMTP placing a semicolon between the server names. If a server port other than 25 is used you can specify this by adding a colon after the server name.
'Out going SMTP mail server address
objJMail.ServerAddress = "smtp.mySMTPserver.com:25"
Next we are going to use the 'Sender' property to let the recipient of the email know who the email is from. If you leave the 'Sender' property out or do not have a properly format email address the email will fail.
'Senders email address
objJMail.Sender = "[email protected]"
The 'SenderName' property is not necessary and can be left out. This property can be used to specify the name of the sender.
'Senders name
objJMail.SenderName = "My Name"
Now we need to place a string value representing the email address of the person you want to receive the email into the 'AddRecipient' property of the 'JMail' object. This needs to be a properly formatted email address, also note the lack of the = sign.
'Who the email is sent to
objJMail.AddRecipient "[email protected]"
The next property 'AddRecipientCC' holds the email address of the people you wish to receive Carbon Copies of the email.
You can repeat this property property on multiple lines if you wish to send carbon copies to more than one person. Make sure all the email address are properly formatted or the email will fail.
This property can be left out if you don't want any carbon copies of the email sent.
'Who the carbon copies are sent to
objJMail.AddRecipientCC = "[email protected]"
The 'AddRecipientBCC' property holds the email address of the people you wish to receive Blind Copies of the e-mail. Like the 'AddRecipientCC' property, this can be repeated on multiple lines for multiple recipients.
Again if you don't want to send any blind copies of the message you can leave this property out.
'Who the blind copies are sent to
objJMail.AddRecipientBCC = "[email protected]"
In the next line we use the 'Subject' property to set the subject of the email.
'Set the subject of the e-mail
objJMail.Subject = "Enquiry sent from my web site"
The JMail component can be used to send mail in either Plain Text or HTML format. I'm going to show you both ways to do it.
First I am going to show you how to send an email in Plain Text format. To do this we use the 'Body' property. If you would rather send the email in HTML format this property can be left and you can use the 'HTMLBody' property instead.
'Set the main body of the e-mail in Plain Text format
objJMail.Body = "Hello." & vbCrLf & "This is my email in Plain Text format"
The next property were covering is the 'HTMLBody' property, this property is for sending the email in HTML format 'eg. <h2>Hello</h2><br><b>This is my e-mail in HTML format</b>'.
'Set the main body of the e-mail in HTML format
objJMail.HTMLBody = "<h2>Hello</h2><br><b>This is my email in HTML format</b>"
The 'Priority' property tells the mail messaging system when to schedule delivery of the email.
For this property there is 3 different integer values, 5 - Low, the e-mail will be sent during times of low system use, 3 - Normal, the message is sent at regular delivery times, 1 - High, the system will attempt to send the message immediately.
If this property is left out the default is Normal.
'Importance of the e-mail (5=Low, 3=Normal, 1=High)
objJMail.Priority = 3
Once all the properties for the email are set we can now send the e-mail using the 'Execute' property.
'Send the e-mail
objJMail.Execute
Finally once the email has been sent we can close the server object releasing server resources.
'Close the server object
Set objJMail = Nothing
%>
There are other methods and properties of the 'Dimac w3 JMail' component but to keep things simple I have tried to cover the most common properties needed to send an e-mail from your web site.
For more information covering all the methods and properties of this component the full documentation can be downloaded from http://www.dimac.net/.