|
ASP Mail and ASP QMail Simple Example 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.
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:
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:
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:
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.
To return form contents in the original form order your code might be...
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. 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 values underlined you can adjust this to work for your timezone. [set other Mailer properties] Notes About Creating the Mailer Object You can create the mailer object at two different points in time:
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:
Creating these local references,
as demonstrated above, allow you to use the object on multiple application
threads at the same time.
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 separated by semicolons. In the event that the primary server is down, AspMail will attempt to use the secondary server. For example:
AspQMail AspQMail uses the AspMail component to send messages to the queue. To use the component you use it the same way you normally would except that you set one additional property.
If QMessage is true then the message will be sent to the \Que directory. If it is false (the default) it will be sent normally via SMTP. More information on ASP Mail and ASP QMail can be found on ServerObjects' web site at: http://www.serverobjects.com/ |