Home | About Us | FAQ
    Products
Development
 
AZ Office:
voice (602) 750-6161
Send an e-Mail
 
   
 

How to Send Email using JMail from Active Server Pages (ASP)


Comsoltech® Incorporated

Summary
This article and ASP script shows how to send email in ASP page, using widely used free JMail component in an easy and simple way to get you started.

Applies To
Active Server Pages (.ASP) envinronment using Windows NT Server, 2000 Server running IIS 4.0, 5.0 or beyond.

Contents

There are several ways you can send email from your ASP environment. If you have access to the NT or Windows 2000 server, you should install a email component. One of the widely used email component, which is also free is Dimac's JMail Component. You can download this component from here: http://tech.dimac.net

If your web site is hosted by some other companies that you don't have access to the server directly, and they do not have JMail component installed, then ask your ISP whether they can install this component. If they don't, then at least they should have CDONTS component installed, which should be installed with Internet Information Server 4.0+ (IIS 4.0+) under Windows NT 4.0 or 2000 server. This lets you send email without any third party component. For article on how to send email using CDONTS component, go to this article.

Assuming you have downloaded this component and installed at the server (Installing in client or workstation will not work!), here's the HTML file that contains initial form, and ASP script that sends the actual email. (No error checking for simplicity. Check documentation on JMail)

Here's mailform.htm file.

mailform.htm

<html>
<form method=post action=sendmail.asp>
From email: <input type=text name=sender><br>
To email: <input type=text name=receiver><br>

Subject: <input type=text name=subject><br>
Body: <textarea name=body></textarea><br>
<input type=submit>
</form>
</html>

After clicking Submit button, this sendmail.asp is executed.

sendmail.asp

<%
' Put your SMTP Mail server here. If you do not know, ask your network administrator
smtpServer = "smtp.yourSMTPServerNameHere.com"
smtpPort = 25


' ---
dim sender, subject, body, smtpServer, smtpPort
' Now gets the data from Form
sender = Request.Form("sender")
receiver = Request.Form("receiver")
subject = Request.Form("subject")
body = Request.Form("body")

Set mail = CreateObject ("JMail.SMTPMail")
mail.ServerAddress = smtpServer & ":" & smtpPort
mail.Sender = sender
mail.Subject = subject
mail.AddRecipient receiver
mail.ContentType = "text/html" ' or you can put 'text/plain' for plain text email
mail.ISOEncodeHeaders = false
mail.ContentTransferEncoding = "8bit"
mail.Body = body

' 1 - highest priority (Urgent) ' 3 - normal ' 5 - lowest
mail.Priority = 3

' Add sender's IP address (not required, but useful for web-based email)
mail.AddHeader "Originating-IP", Request.ServerVariables ("REMOTE_ADDR")

' Actually send mail
mail.Execute
set mail = nothing

Response.write "Email sent OK!"
%>

Good luck, and happy programming!
Comsoltech® Inc
http://www.comsoltech.com


(C) 1998 - 2010 Comsoltech® Incorporated. All Rights Reserved. info@comsoltech.com
Comsoltech is a registered trademark of Comsoltech Incorporated.
Home | Products | Development
4Templates.com   | Save on QuickBooks Products + Free Shipping