<% '======================================================== ' JMail example script. V 0.0.2 - beta '======================================================== ' This script can be used to send an email from a webform ' within your website. eg. contacts page, registration page ' or from any other form of your choosing. Information is ' sent from your webform to this page which in turns generates ' an email and redirects viewers to a thank you page. ' ' Please remember to use the details that are relavent ' to your domain. ' ' This page is written in ASP and requires a server that ' supports this technology. All Acenet accounts ' (except the freedom package) support ASP scripting. ' '======================================================== ' EXAMPLE.COM '======================================================== ' Throughout this script you will see references to example.com ' Example.com is a reserved domain name for the purposes of ' writing documentation on the internet. ' ' Please subsitute your domain name where you see example.com ' You will need to enter this required infromation in the ' fields below. Each item that requires details will have ' a comment explaining what the variable does and an example ' of the type information to be entered. The details will be ' issed by your provider once your account is setup. ' ' More details can be found at: ' http://www.example.com/ ' and ' http://www.rfc-editor.org/rfc/rfc2606.txt ' '------------------------------------------------------- ' Some variables required for processing this script '------------------------------------------------------- ' Dim Item Dim YourName Dim EmailAddress Dim From Dim Subject Dim Body Dim Jmail Dim MailServer Dim FinishPage Dim newline newline = chr(13) + chr(10) '------------------------------------------------------- ' In order for this script to work you will need to ' fill in the details below. ' ' This script is designed to have information sent FROM ' a web form TO this page for processing. The information ' is sent via the POST method. You can use the example ' webform as a template if you are unsure on how to setup this up. ' ' If you want a valid senders email address you can ' included a text box in your form labelled as "EmailAddress". ' See the script-example\webform.htm site for more details. ' ' NOTES: If you are in doubt about what to put in any of the ' fields then you can leave it blank. This script will work ' straight of the shelf. If you leave the details blank the ' script will use the following as defaults. ' ' EmailAddress = "postmaster@example.com" ' From = "webform@example.com" ' MailServer = "mail.example.com" ' contact your ISP for your details. ' Subject = "" ' not required but annoying not to have. '------------------------------------------------------- ' This is the address of the person who will be ' recieving this email. Is the message being sent to you? ' Then you will will need to enter in your email address below. ' ' By default this script will email ' postmaster@yourdomain.com at your domain. ' Example: EmailAddress = "destination@example.com" EmailAddress = "" ' Where will this email message come from? ' Please specify a correct address for the email Sender ' or From address. if you are not sure leave this field ' blank. By default this script will use ' "webform" at your domain (ei webform@yourdomain.com). ' ' Example: From = "sender@example.com" From = "" ' ******************************** ' NOTE: ' If no information is entered above the script will attempt to ' to look for a form field called EmailAddress otherwise it will use ' "postmaster" at the domain that this script is hosted on. ' ******************************** ' Type in your mail server address. If you do not know your ' your mail server try leaving this field empty. Contact your provider ' for the exact details. ' Example: MailServer = "mail.example.com" MailServer = "" ' The Subject line for the email. ' ' Example: Subject = "Contact Form" Subject = "Contact Form" ' Type in the name of the page you want to display after ' the form has been processed and emailed. ' *This Field is optional and can be left blank. ' A thank you note will be displayed by default. FinishPage = "" '--------------------------------------------- ' That's it. The remainer of this file is used ' for the processing of your email. ' Please ensure that you have entered valid ' information in the fields above. ' ' Comments have been included below if you ' would like find out more about this script ' works. ' '--------------------------------------------- ' ' This will extract every form element from the ' submitting web form and add them to the body of the ' message with the label name and it's value on seperate ' lines (eg. Label:Value) ' '--------------------------------------------- For Each item In Request.Form body = body & item & " : " & Request.Form(item) & newline Next ' Check that the from address is valid, otherwise use ' webform@example.com This code will check that ' we have a 'From' address. Preferable use a textbox ' in your web form with the label name="EmailAddress" ' example: ' If you have used an "EmailAddress" field in your form ' you need to ensure that the 'From' variable is left blank. If From = "" Then If Request.Form("EmailAddress") <> "" Then From = Trim(Request.Form("EmailAddress")) Else From = "webform@" & Replace(Request.ServerVariables("SERVER_NAME"), "www.","") End if End if If YourName <> "" Then If Request.Form("Name") <> "" Then YourName = Trim(Request.Form("Name")) End if End If On Error resume Next ' Exception handling ' Create a JMail object Set JMail = Server.CreateObject("JMail.SMTPMail") ' Initialise JMail object with the details provided above. If MailServer = "" Then JMail.ServerAddress = "mail." & Replace(Request.ServerVariables("SERVER_NAME"), "www.","") Else JMail.ServerAddress = MailServer End if If EmailAddress = "" then EmailAddress = "postmaster@" & Replace(Request.ServerVariables("SERVER_NAME"), "www.","") End if ' rack em up and send it out. JMail.Sender = From JMail.Subject = Subject JMail.AddRecipient EmailAddress JMail.Body = Body JMail.Priority = 3 JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR") JMail.Execute If Err.Number <> 0 then Response.Write("") Response.Write("") Response.Write("") Response.Write("") Response.Write("") Response.Write("") Response.Write("") Response.Write("
Mail configuration Error.
Error #" & CStr(Err.Number) & "
Error Description" & Err.Description & "
JMail.Recipient:" & EmailAddress & "
JMail.Sender:" & JMail.Sender & "
JMail.ServerAddress:" & JMail.ServerAddress & "
JMail.Subject:" & JMail.Subject & "
") Else ' Finally we need to transfer you to the finish page or drop a message letting you ' know that we have completed the task. If FinishPage <> "" then Err.Clear On Error Goto 0 ' turn off exception handling. Response.Redirect FinishPage Else Response.Write("

Thank You

Your details have been submitted and you will be contacted shortly. Thank you

") End If End if Err.Clear On Error Goto 0 ' turn off exception handling. %>