Web Wiz - Solar Powered Eco Web Hosting

Classic ASP Web Based Email using Dimac w3 JMail 4+

Difficulty: Medium
Download: Web Wiz JMail Forms_(JMail)

If you are reading this page then I shall assume that you already know a little bit about ASP and running ASP applications.

The download to this tutorial has a working example of Web Wiz JMail 4+ Form which you can use to allow your website visitors to send their comments or enquiries.

However, I am not going to go into how the form is written as it uses standard HTML and JavaScript to capture the users details. Instead I'm going to concentrate on the actual methods and properties the w3 JMail 4+ object uses to format and then send the email.

The Dimac w3 Jmail 4+ component is available for free from www.dimac.net. You will also need an SMTP server to send the mail messages through, your ISP or web hosts should be able to supply you with one so contact them for the details.

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.Message")

Most SMTP mail servers require authentication to send emails to prevent those mail servers being used by spammers. Use the properties below to enter the username and password for the SMTP mail server that you are using.

'SMTP Server Authentication - Username and Password
objJMail.MailServerUserName = "ADD SMTP USERNAME HERE"
objJMail.MailServerPassword = "ADD SMTP PASSWORD HERE"

Next we are going to use the 'From' 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.From = "myself@example.com"

The 'FromName' property is not necessary and can be left out. This property can be used to specify the name of the sender.

'Senders name
objJMail.FromName = "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 "theirEmail@theirDomain.com"

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 "myFriend@theirDomain.com"

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 "myFriend@theirDomain.com"

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 website"

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 email to the SMTP server that is sending the email for you. If a server port other than 25 is used you can specify this by adding a colon after the server name.

'Send the e-mail

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 website.

For more information covering all the methods and properties of this component the full documentation can be downloaded from www.dimac.net.


Become a Fan on Facebook Follow us on Twitter Connect with us on LinkedIn Community Forums Web Wiz Blogs Web Wiz News
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2019 Web Wiz Ltd. All rights reserved.