Sending Email from a Webpage using ASP
This page will provide instructions on how to send mail from your website using Chilisoft ASP and the Microsoft equivalent mail component W3Jmail running on the IIS cluster.
Windows IIS servers for MS ASP users - W3Jmail component
For customers on the Windows server, wishing to send email from a webpage, we recommend you use the following code.
<%@LANGUAGE = VBSCRIPT%>
<html>
<body>
<%
DIM strEmail, strFirstName, strLastName, strSubject, strComments, Mailer
strEmail = Request.Form("Email")
strFirstName = Request.Form("FirstName")
strLastName = Request.Form("LastName")
strSubject = Request.Form("Subject")
strComments = Request.Form("Comments")
set msg = Server.CreateOBject( "JMail.Message" )
msg.From = strEmail
msg.FromName = strFirstName
msg.AddRecipient "user@domain.com" <mailto:user@domain.com>
msg.Subject = strSubject
msg.Body = Comments
if not msg.Send("localhost" ) then
Response.write "<pre>" & msg.log & "</pre>"
else
Response.write "Message sent succesfully!"
end if
%>
Unix Apache for Chilisoft ASP users - ChiliMail component:
Simple Mail Transfer Protocol COM object used to send emails from an ASP page to an email server.
The Chili!Soft Mail 1.1 ActiveX Control enables users to create and send email messages via SMTP from ASP scripts. The Chili!Soft Mail control is designed to be closely compatible with the NewMail object that is included with the Microsoft IIS CDONTS component.
The Chili!Soft Mail Control does not support the following NewMail properties and methods at all:
1. BodyFormat
2. ContentBase
3. ContentLocation
4. MailFormat
5. Version
6. AttachURL
7. SetLocaleIDs
Other differences between the controls are noted in the individual Property and Method descriptions that follow.
The control makes use of no registry settings.
The Chili!Mail 1.1 ActiveX Control is registered with the ProgId of "CDONTS.NewMail". The following VBScript excerpt shows creating an instance of the control.
Set mailer = Server.CreateObject("CDONTS.NewMail")
The Chili!Mail 1.1 ActiveX Control exposes the following properties and methods:
Properties:
(String: Read/Write)
The value you use to set the To property can represent a single recipient or a list of recipients. Each recipient must be represented by a full messaging address:
"useraddress@company.com"
Multiple recipients on the list are separated by semicolons:
"user1@company1.com;user2@company2.com;user3@company3.com"
If both the To property and the To parameter of the Send method are supplied, the mail message is sent to all recipients on both lists.
(String: Read/Write)
A string of what should be sent as the From part of the message header. May not include spaces.
(String: Read/Write)
The value you use to set the Cc property can represent a single recipient or a list of recipients. Each recipient must be represented by a full messaging address:
"useraddress@company.com"
Multiple recipients on the list are separated by semicolons:
"user1@company1.com;user2@company2.com;user3@company3.com"
(String: Read/Write)
The value you use to set the Bcc property can represent a single recipient or a list of recipients. Each recipient must be represented by a full messaging address:
"useraddress@company.com"
Multiple recipients on the list are separated by semicolons:
"user1@company1.com;user2@company2.com;user3@company3.com"
(String: Read/Write)
A string to be sent as the subject line of the message. May be left empty.
(String: Read/Write)
The symbolic name (e.g. "mail.myorg.com") or ip address (ww.xx.yy.zz) of the SMTP mail server the control should use to send the message. Defaults to "localhost".
(String: Read/Write)
The text portion of the message to be sent. Line breaks should be sent as LINEFEED characters ( "Chr(10)" ).
CDONTS Note: the Body property in the Chili!Soft implementation must be text. There is no option for sending HTML, nor for providing an IStream object as input for this property.
(Read/Write)
The Value property is used to add one or more headers to the automatically generated headers such as "To", "From", "Subject", and "Date". Possibilities for additional headers include "File", "Keywords", and "Reference".
Certain headers, such as "Reply-To", are widely accepted and used by various messaging systems. If you wish such a header to be recognized by the recipients of the NewMail object, you must be sure that the character string in the header's name exactly matches the accepted string.
In principle you can put any combination of ASCII characters in the string, but some messaging systems may have restrictions on the character set. The safest procedure is to limit the string to alphanumeric characters, dashes, and slashes, and in particular to avoid spaces.
You can set the Value property more than once. Each setting generates another header to be included with the existing headers.
- Importance
(Long: Read/Write)
The importance of the message to be sent. Valid values are:
- 0 Low Importance
- 1 Normal Importance
- 2 High Importance
- Retain
(BOOLEAN: Read/Write)
If set to True, all of the properties will be retained after the Send method is called. If set to False (the default), all properties are cleared after the Send method is called.
Methods:
- AttachFile
Adds a file attachment to the message. Messages are multi-part mime encoded, and attachments follow the text portion of the message.
Arguments:
Source |
A string containing the full path and filename of the file that should be attached to the message. |
CDONTS Note: The Source argument can only be a string. There is no provision for providing an IStream pointer as a source for the file to attach. All messages are encoded Base64. There is no provision for specifying a different encoding method.
- Send
Send the message using the properties previously set. All arguments to this method are optional and override the properties previously set for the message (with the exception of the "To" argument, which is combined with any previously set "To" property.
Calling the Send method re-sets all message properties in preparation for the next message, unless the Retain property is set to True. Multiple messages may be sent using the same instance of the Chili!Soft Mail control.
Arguments:
From |
See the description of the property of the same name above. |
To |
See the description of the property of the same name above. |
Subject |
See the description of the property of the same name above. |
Body |
See the description of the property of the same name above. |
Importance |
See the description of the property of the same name above. |
Host |
See the description of the property of the same name above. |
Example 1: You can modify the From, To, Subject and Body lines, but you must leave the others as they are, in particular the CreateObject must stay as it is.
<%
set objMail=CreateObject("CDONTS.NewMail")
objMail.From="whoever@yourdomain.com"
objMail.To="whoever@yourcustomer.com"
objMail.Subject="Your Subject"
objMail.Body= "This is a test message." & Chr(10) & "This is the second line."
objMail.Host = "localhost"
objMail.Send
set objMail=Nothing
%>
|