MyEspinda! .Customers Login Here

ASP Scripting With JMail

General Scripting Information

The scripting information provided here is aimed at Espinda' customers. Much of the code is applicable to any Windows based Web Server. However some parameters, such as the methods used to derive the names of the SMTP servers, may not be valid.
Our ASP scripts are all written in VBS; we provide no JScript equivalents. We do provide Perl equivalents using the same technologies. Perl users should now use the JMail object in place of BLAT for sending mail from their scripts. If you currently use Blat, please change it.

The code uses JMail version 3. This is the current version installed on the servers. Detailed component information can be obtained from the Dimac site - http://www.dimac.net.

Before we go into detail on how to get your form working, let's look at some ground rules that will ensure your mail isn't blocked:

* Espinda redirects all web based mail to an SMTP Filter System. Mails must have either a valid "from" or "to" address which is a domain hosted with Espinda. Any mail that doesn't fulfil these criteria is dropped. If you are sending mail to a customer who has given you his email address, you need to use the domain name of the site (note that it does not need to be a valid mailbox on the account) noreply@domain.tld is a fairly common one to use. Remember to use a valid account if you want the customer to reply to the email.

* Espinda' SMTP Filter System rate limits outgoing mail from any domain. This prevents bulk emailing. Our limits are set to allow normal form based email activity to pass unhindered, but stop any persistent attempt to send bulk mail.

* Do not use your site for mass emailing (spam). The SMTP Filter System will prevent this, and the information gets logged. Attempting to bulk email will lead to your site being closed by our abuse department.


Using JMail in ASP to Provide Email on Your Site

The first thing to do is to make sure your form in the submitting page is correct. In its simplest form it should look like:

<form action="jmail.asp" method="post" name="mailform">
<input name="email" type="text" size="40">
<input name="email_submit" type="submit" value="send mail">
</form>

Now to the real scripting. Using the example submit form above, this is the code in the jmail.asp file. First initialize the variables - though this isn't strictly necessary, its good programming practice to do so.

dim JMail, intComp, strReferer, strServer, strClientIP, strServerIP, blnSpam

Next set up the jmail object.

Set JMail = Server.CreateObject("JMail.SMTPMail")

After that obtain some information about the site using the request.servervariables object. Note that we get the referrer page here. This is the page that carried out the page post operation.

strReferer = request.servervariables("HTTP_REFERER")
strServer = Replace(request.servervariables("SERVER_NAME"),"www.","")
strClientIP = request.servervariables("REMOTE_ADDR")
strServerIP = request.servervariables("LOCAL_ADDR")

Now use this information to check that the posting page is on the same site as the script. This prevents others using your script for bulk emailing activities - see the note at the bottom of this page.

intComp = inStr(strReferer, strServer)
If intComp > 0 Then
blnSpam = False
Else
' Spam Attempt Block
blnSpam = True
End If

Next populate the jmail object with the correct data. Note that we use the server information to set up the sender and the SMTP server. The recipient is obtained from the request object.

JMail.ServerAddress = "smtp." & strServer & ":25"
JMail.Sender = "noreply@" & strServer
JMail.Subject = "JMail Example" & " Sent @ " & now()
JMail.AddRecipient request.form("email")
JMail.Body = "This test mail sent from: " & strServerIP & " using the JMail component on the server."
JMail.Priority = 3
JMail.AddHeader "Originating-IP", strClientIP

This bit of code checks the referrer is correct, and if so sends the mail to the smtp server.

If NOT blnSpam Then
JMail.Execute
strResult = "Mail Sent."
Else
strResult = "Mail Not Sent."
End If

After outputting whatever text you want to tell the client that the job is done, clean up the objects we have used.

set jmail=nothing

That's it.

Note - If you don't protect your scripts by checking the referrer, you will leave them open to abuse by bulk mailers. If this happens you site may be closed by our abuse department.


Full Code

<!-- ASP Code Section -->

<%
'initialise objects and variables
dim JMail, intComp, strReferer, strServer, strClientIP, strServerIP, blnSpam
Set JMail = Server.CreateObject("JMail.SMTPMail")

'code to check if this page is being called from a another page on the server
strReferer = request.servervariables("HTTP_REFERER")
strServer = Replace(request.servervariables("SERVER_NAME"), "www.", "")
strClientIP = request.servervariables("REMOTE_ADDR")
strServerIP = request.servervariables("LOCAL_ADDR")
intComp = inStr(strReferer, strServer)
If intComp > 0 Then
blnSpam = False
Else
' Spam Attempt Block
blnSpam = True
End If

' This is my local SMTP server
JMail.ServerAddress = "smtp." & strServer & ":25"

' This is me....
JMail.Sender = "noreply@" & strServer
JMail.Subject = "JMail Example" & " Sent @ " & now()

' Get the recipients mailbox from a form (note the lack of a equal sign).
JMail.AddRecipient request.form("email")

JMail.Body = "This test mail sent from: " & strServerIP & " using the JMail component on the server."
JMail.Priority = 3

JMail.AddHeader "Originating-IP", strClientIP

'send mail
If NOT blnSpam Then
JMail.Execute
strResult = "Mail Sent."
Else
strResult = "Mail Not Sent."
End If

%>
<!-- HTML Output Section -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Xtreme Email Test</title>
</head>
<body topmargin="0" leftmargin="0" style="font-family: Verdana; font-size: 8pt">

<br>
<%=strResult%><br>
SMTP Server: <%=JMail.ServerAddress%><br>
SenderIP: <%=strClientIP%><br>
ServerIP: <%=strServerIP%><br>
Server: <%=strServer%><br>
Referer: <%=strReferer%><br>
Receiver: <%=request.form("email")%><br>
Sender: <%=JMail.Sender%><br>
<br><br>

<a href="jmail.htm">Return to email page</a>

<%
set jmail=nothing
%>

</body>
</html>

Home|About Espinda|Hosting Plans|Tools|FAQ|Contact|Support|Terms of Service|Site Map|Order