AspMail
3.x
Welcome
to DreamWorx Hosting's AspMail Tutorial. AspMail allows you to send mail using
the standard SMTP protocol from any program that can use ActiveX/OLE components.
Features include:
- SMTP (sending)
Messages
- Multiple File
Attachments
- File attachments
support MIME and UUEncoding
- US Ascii and
ISO-8859-1 character sets
- PGP
- Subject line
encoding for 8bit message subjects
- Redundant
SMTP servers (If the primary SMTP server is down, the secondary server is
used)
- Special Header
Support (Standard X-Priority headers, MS Mail (including Exchange) priority
headers, Urgent header, ConfirmReading and ReturnReceipt Headers)
- Multiple concurrent
users (Tested with 15 concurrent connections)
Changes
in AspMail 3.0
- Better support
for MTS. Transactions are not supported in the 3.0 release but you should
be able to incorporate AspMail into MTS packages without any troubles.
- Better COM
support. AspMail is now more compatible with VC, VFP, VB, PowerBuilder and
other development systems besides ASP.
AspMail
Installation
To use this ASP component move the DLL into a subdirectory (like
\winnt\system32 for NT or \windows\system for Win95). Please use the version
of regsvr32 that is included with this component or the version that comes
with Microsoft ASP (they are the same version). To
register the component on the system change to the directory where you installed
the DLL and type:regsvr32
smtpsvg.dll
Make sure your TMP or TEMP envinronment variable is set up as a system
variable if you are running WinNT. You can use our troubleshooting utility
for a simple way to configure this, or if you want to do it manually, you
can follow these instructions:
- Start Control
Panel
- Double-click
on the System icon
- Select the
Environment tab
- View the system
variables in the top pane on the form. Do not concern yourself with User
variables, the 2nd pane on the form.
- If a TMP or
TEMP var does not exist
- Single
click one of the variables in the System list
- Move to
the Variable field, select the existing text and overwrite
it with TMP. This will not replace the existing variable, it will add
a new variable named TMP.
- Move to
the Value field. Enter the path of your temporary directory.
- Click
the Set button.
- Restart
the server.
Simple Mail Example
Using the
component is as simple as
- Creating the
object
- Setting a
few properties
- Calling the
SendMail method
The following
code demonstrates how to use AspMail from VBScript. In this example Joe from
Joe’s Widgets wishes to send an email to John Smith. Joe’s mail
server is located at mailhost.localisp.net.
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "Joe’s Widgets Corp."
Mailer.FromAddress= "Joe@somehost.com"
Mailer.RemoteHost = "mailhost.localisp.net"
Mailer.AddRecipient "John Smith", "jsmith@anotherhostname.com"
Mailer.Subject = "Great SMTP Product!"
Mailer.BodyText = "Dear Stephen" & VbCrLf & "Your widgets order has
been processed!"
if Mailer.SendMail then
Response.Write "Mail sent..."
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
By testing
the result of the SendMail method we can determine if the mailing process
was successful or not.
Form Handling
All or partial input for a message may come from a form. For example, a form
posted to the server with a request method of GET (i.e. <form action="/scripts/AspMail.asp"
method=get>) may provide the message recipient’s email address, subject
and message text as follows:
Mailer.AddRecipient Request.QueryString("ToName"), Request.QueryString("ToAddress")
Mailer.Subject = Request.QueryString("Subject")
Mailer.BodyText = Request.QueryString("MsgBody")
The form
may also use the POST method (i.e. <form action="/scripts/AspMail.asp"
method=post>) in which case the code would look as follows:
Mailer.AddRecipient Request.Form("ToName"), Request.Form("ToAddress")
Mailer.Subject = Request.Form ("Subject")
Mailer.BodyText = Request.Form ("MsgBody")
You can
use any mixture of static and dynamic data in setting the components properties
as dictated by your needs. For example, you may wish to send the mail to a
single user. In this case you could modify the code to look something like
this:
Mailer.AddRecipient "John Smith", "jsmith@alocalhost.com"
Mailer.Subject = Request.QueryString("Subject")
Mailer.BodyText = Request.QueryString("MsgBody")
Generic
Form Handling
In some cases users may wish to use a number of different forms to send email
with the same block of code. ASP allows you to loop through each QueryString
or Form variable and append each one to string variable which is then assigned
to the BodyText property. Please note: AspMail cannot control the order that
these variables are returned in. This is a function of ASP, not AspMail. ASP
takes the form variables and creates the appropriate Request collection (QueryString
or Form) and stores the data in an order that AspMail cannot change. If you
use this method you must accept ASP's order.
strMsgHeader = "Form information follows" & vbCrLf
for each qryItem in Request.QueryString
strMsgInfo = strMsgInfo & qryItem & " - " & request.querystring(qryItem)
& vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter
Setting
Mail Priority
There are a couple of headers that can be modified to set message priority.
The Priority property sets the message priority on a scale of 1 to
5. A priority of 1 means HIGH. A priority of 3 means NORMAL and a priority
of 5 means LOW. In addition to this you can also set the Urgent property
if the message status is urgent. The Urgent property is a true/false
property.
How to Use
the DateTime Property
The component creates a Date/Time value for the message based on the calculated
GMT time. The DateTime property was added to allow users to set a custom date/time
timezone. The following code demonstrates how to set the DateTime to US Central
Standard Time. By slightly altering the code you can adjust this to work for
your own timezone.
function DayName
(intDay)
select case intDay
case 1
DayName = "Sun"
case 2
DayName = "Mon"
case 3
DayName = "Tue"
case 4
DayName = "Wed"
case 5
DayName = "Thu"
case 6
DayName = "Fri"
case 7
DayName = "Sat"
end select
end function
function MonthName (intMonth)
select case intMonth
case 1
MonthName = "Jan"
case 2
MonthName = "Feb"
case 3
MonthName = "Mar"
case 4
MonthName = "Apr"
case 5
MonthName = "May"
case 6
MonthName = "Jun"
case 7
MonthName = "Jul"
case 8
MonthName = "Aug"
case 9
MonthName = "Sep"
case 10
MonthName = "Oct"
case 11
MonthName = "Nov"
case 12
MonthName = "Dec"
end select
end function
[set other Mailer properties]
Mailer.DateTime = DayName (WeekDay(Date)) & ", " & Day(Date) &
" " & MonthName(Month(Date)) & " " & Year(Date) & " " &
FormatDateTime(Now, 4) & " -0600 (CST)"
Mailer.SendMail
Notes
About Creating the Mailer Object
You can create the mailer object at two different points in time:
- Immediately
before sending an email
- At the session
scope and saved as a session object
You will have
to decide when and where it is appropriate to create the object based on your
particular application. If you aren't sure which way to create the object
reference, or for typical usage, you should create the object immediately
before sending your email. Your code would look like this:Set
Mailer = Server.CreateObject("SMTPsvg.Mailer")
... [Set properties]
if Mailer.SendMail then ...Creating
these local references, as demonstrated above, allow you to use the object
on multiple application threads at the same time.To
create an object reference at the session level, your code might look something
like this:
if Not IsObject
(session("Mailer")) then
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Set session("Mailer") = Mailer
else
Response.write "Cached session object reference being used<p>"
Set Mailer = session("Mailer")
end if
Multiple
Host Support
AspMail provides one host property to set up remote SMTP server addresses.
The RemoteHost property should be set to your primary and secondary
server’s address seperated by semicolons. In the event that the
primary server is down, AspMail will attempt to use the secondary
server. For example, Mailer.RemoteHost
= "mailhost.localisp.com;mailhost.anotherisp.com"
PGP
Support
AspMail now supports PGP. See the pgpmail.asp script for an example of
usage. ServerObjects Inc. is not responsible for PGP support. If you have
questions about PGP please contact the developers of PGP. About
purchasing AspMail
- The registration
license fee covers only one CPU per license. The fee per CPU
is $49.95. We have priced the component at a level where we hope that companies
or individuals using multiple copies will respect the license agreement.
- Evaluation
copies will expire. See the Expires property for details on determining
when your copy will expire.
- Attachments
are enabled in the registered version but not in eval copies.
About Upgrades
- Users can
upgrade for free for minor version changes. For example, upgrades from version
1.00 to 1.99 are free. The upgrade from 2.x to 3.x may carry a upgrade
fee.
- The latest
version of the components are always available at http://www.serverobjects.com/products.htm.
If a fee is associated with obtaining the upgrade it will be noted
on that page.
Upgrade Instructions
To upgrade the component from a previous version please follow these steps:
- Stop all IIS
related services such as Gopher, FTP and W3SVC.
- Change to
the directory where the component is located and type "regsvr32 /u smtpsvg.dll"
- Move the new
copy of smtpsvg.dll to the current directory and type "regsvr32 smtpsvg.dll"
- If you were
using AspMail 1.x, be sure and modify any code that uses the Recipient,
CC and BCC properties to use the new methods.
- Restart the
necessary services.
Questions
about AspMail
See http://www.serverobjects.com/TechComm.htm
for general ASP support errors and issues. Download
our troubleshooting utility
for help with configuration problems.
|