% '======================================================== ' JMail with SmartUp example script. V 0.0.1 - beta '======================================================== ' JMail with SmartUp example script. ' This script can be used to send an email from your ' contacts page or any other webpage of your choosing. ' This script will also attach a file of your choosing. ' Please remember to use the details that are relavent ' to your domain. ' ' This page will only process information when hosted ' on a server that supports asp otherwise you will see ' these comments instead. ' '------------------------------------------------------- ' Some variables required for processing this script '------------------------------------------------------- ' Dim Item Dim YourName Dim YourEmailAddress Dim From Dim Subject Dim Body Dim Jmail Dim MailServer Dim FinishPage Dim mySmartUpload 'declare the SmartUpload component Dim File 'declare the file to upload Dim tempLocation ' the folder that will store your temporary files. Dim filename 'Temp filename Dim fs Dim f Dim FileNameTitle Dim ContentType Dim newline newline = chr(13) + chr(10) On Error resume Next ' Exceptions are now being handled ' Initialise the objects Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload") ' Create a SmartUpload object ' limit the total upload to 200 Kb, larger sizes are not recommended. ' -- We have tested the email script and have found that files up to 2meg seem to work okay. ' Limit set to: mySmartUpload.MaxFileSize = 200000 mySmartUpload.TotalMaxFileSize = 200000 ' This is a basic list of usable files. It is also ways a good idea to ' to block pif and bat files. It is strongly recommended to block .exe ' files as well. For security reasons you should limit the types of files ' allowed to those that you really need to use. ' Limit the file extensions to: mySmartUpload.AllowedFilesList="gif,jpg,doc,txt,zip,htm,html" mySmartUpload.DeniedFilesList="exe,pif,bat" 'Upload the selected file to the server mySmartUpload.Upload Set JMail = Server.CreateObject("JMail.SMTPMail") ' Initialise JMail object with the details provided above. '------------------------------------------------------- ' 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 POST. 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. ' ' This script will contact the webserver to find yourdomain name ' instead of example.com ' ' YourName = "" ' not required to send an email message. ' YourEmailAddress = "postmaster@example.com" ' From = "webform@example.com" ' MailServer = "mail.example.com" ' Subject = "" ' not required but annoying not to have. '------------------------------------------------------- 'The name in front of the email address. '* This field is optional and can be left blank. 'Example: YourName = "Fred Smith" YourName = "" 'Type in your email address. This is the address of the 'person that you want to recieve this email. 'By default this script will email ' webform@yourdomain.com at your domain. ' Example: YourEmailAddress = "fredsmith@example.com" YourEmailAddress = "" ' Please specify a correct address for the email Sender ' or From address. This Field is optional and can be left blank. ' ' Example: YourEmailAddress = "fredsmith@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. ' Example: MailServer = "mail.example.com" MailServer = "" ' Subject line for the email. ' Example: Subject = "Contact Form" Subject = "Contact Form" ' We will now need to select a location to store the temporary files on the web server. ' This directory will be located relative to your website and not the file server. ' You may need to contact Acenet or your service provider in order to setup this directory. ' ' Example. tempLocation = "temp" (this indicates the file "www.example.com/temp/") tempLocation = "temp" ' 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. 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) ' 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 Trim(mySmartUpload.Form("EmailAddress")) <> "" Then From = Trim(mySmartUpload.Form("EmailAddress")) Else From = "webform@" & Replace(Request.ServerVariables("SERVER_NAME"), "www.","") End if End if If MailServer = "" Then JMail.ServerAddress = "mail." & Replace(Request.ServerVariables("SERVER_NAME"), "www.","") Else JMail.ServerAddress = MailServer End if If YourEmailAddress = "" then YourEmailAddress = "postmaster@" & Replace(Request.ServerVariables("SERVER_NAME"), "www.","") End if If YourName <> "" then YourEmailAddress = YourName & " " & YourEmailAddress ' don't forget the space! End If ' Now we check the files being uploaded before writing them to disk. ' This section of code will cause errors if you do not have the correct ' file permissions set. Please contact your hosting provider for more details. ' map the path we are using. For each File In mySmartUpload.Files If not File.IsMissing then File.SaveAs("/" & tempLocation & "/" & File.FileName) ' this can cause errors if two documents are labelled the same ' TODO: impliment script using session.sessionID JMail.AddAttachment Server.MapPath("/" & tempLocation) & "\" & File.FileName FileNameTitle = File.FileName ContentType = File.ContentType End If Next ' error managment. Error messages are included with the email. If not Err.Number = 0 then body = body & "There were errors with the attachment" & newline body = body & "Please contact the client and request they resend the file." & newline body = body & "Error : " & Err.description & newline body = body & JMail.ErrorMessage & newline End if ' 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 mySmartUpload.Form ' Select each value of the current item For each value In mySmartUpload.Form(item) if Trim(value) <> "" then body = body & item & ": " & value & newline End if Next Next If Trim(FileNameTitle) <> "" then body = body & "Attachment: " & FileNameTitle & newLine body = body & "ContentType: " & ContentType & newLine End if ' now destroy the smartupload object Set mySmartUpload=nothing ' remove the file that was uploaded by the web form Set fs=Server.CreateObject("Scripting.FileSystemObject") If fs.FileExists(Server.MapPath(tempLocation) & "\" & FileNameTitle) then fs.DeleteFile(Server.MapPath(tempLocation) & "\" & FileNameTitle) If fs.FileExists(Server.MapPath(tempLocation) & "\" & FileNameTitle) then body = body & "Web site failed to complete the removal of the application sent to you. Please login to the website and check htmlPages/upload/ for any excess files." & newline End if End if Set fs = nothing JMail.Sender = From JMail.Subject = Subject JMail.AddRecipient YourEmailAddress JMail.Body = Body JMail.Priority = 3 JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR") JMail.Execute If Err.Number <> 0 then Response.Write("
| Mail configuration Error. | |
|---|---|
| Error # | " & CStr(Err.Number) & " |
| Error Description | " & Err.Description & " |
| JMail.Recipient: | " & YourEmailAddress & " |
| JMail.Sender: | " & JMail.Sender & " |
| JMail.ServerAddress: | " & JMail.ServerAddress & " |
| JMail.Subject: | " & JMail.Subject & " |
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. %>