ASP Email - JMail
JMail is a popular ASP component available on many of todays web hosts. You can download a free copy of JMail from the Dimac Website to test email scripts on your own server. This ASP tutorial will show you how to send messages using the JMail component.
Let's start by creating a new mail object:
<%
Set oJMail = Server.CreateObject("JMail.SMTPMail")
%>
Now we've created the email object, we can start adding addresses. We can add multiple recipients by using more than one of the AddRecipient, AddRecipientCC (carbon copy) or AddRecipientBCC (blind carbon copy) methods.
You can also make your own name appear in the "From" field of the message by using the SenderName property:
<%
with oJMail
.Sender = "you@yourdomain.com"
.SenderName = "Your name"
.AddRecipient "someone@domain.com"
.AddRecipient "someone.else@domain.com"
.AddRecipientCC "someone@anotherdomain.com"
.AddRecipientBCC "another@somedomain.com"
end with
%>
Here we set the subject and message priority. The priority is a number from 1 to 5, with 1 being high priority and 5 being low.
To send plain text email use the Body property and to send HTML email, use the HTMLBody property. We can also attach a file to the message using the AddAttachment method:
<%
with oJMail
.Subject = "This is my subject"
.Priority = 3 ' 1=high, 3=normal (default), 5=low
.Body = "Here is my message"
.HTMLBody = "<strong>Here is my message!</strong>"
.AddAttachment "C:\Inetpub\wwwroot\attachment.zip"
end with
%>
The last property to set is the SMTP server address and port. If you are sending email from your own server, try using "localhost" as the ServerAddress property - otherwise ask your web host what their SMTP server address and port are. The default port is 25.
This is now enough information to send the message, so now we can send the email using the Execute method:
<% oJMail.ServerAddress = "smtp.yourdomain.com:25" oJMail.Execute Set oJMail = Nothing %>
Now the email has been sent, all we need to do is destroy the mail object.

