Send mail using JMail

Below is a simple script example for sending email using JMail on our Windows servers...

 

You can use this in your own scripts- A brief description of each parameter required...

 

sTo : A single email address to send to, this has simple validation to make sure there is not more than one address to prevent hijacking

sFrom : The address the is to be sent from

 

NOTE : Either the To or From address needs to be based on the domain you are sending from

 

sSubject : The subject line for the email

 

sPlainBody : The plain text version of the email, can be left empty if required

 


sHTMLBody : The HTML version of the email, can be left empty if required


Sub emailTo (sTo, sFrom, sSubject, sPlainBody, sHTMLBody)
gSMTPserver = "mail.dc-servers.com"
' Enter values below if SMTP authentication is required
gSMTPauthUser = "
gSMTPauthPass = "
If sTo <> " Then
If InStr(sTo, ",") > 0_
Or InStr(sTo, ";") > 0_
Or InStr(sTo, " ") > 0_
Or InStr(sTo, Chr(10)) > 0_
Or InStr(InStr(sTo, "@") + 1, sTo, "@") > 0 _
Then
' Do not send email, may want to log this...
' This is a possible email hijack
Response.Write ("Error:Email not sent")
Else
' Carry on and email
Set JMail = CreateObject("JMail.Message")
JMail.AddRecipient sTo, sTo
JMail.From = sFrom

JMail.Subject = sSubject
If Len(sPlainBody) > 0 Then
JMail.Body = sPlainBody
End If

If Len(sHTMLBody) > 0 Then
JMail.HTMLBody = sHTMLBody
End If

If Len(gSMTPauthUser) > 0 Then
JMail.MailServerUserName = gSMTPauthUser
JMail.MailServerPassword = gSMTPauthPass
End If

If not JMail.Send(gSMTPserver) then
' There was an error - print the error log
Response.write ("Error:" & JMail.log)
End If

Set JMail = Nothing
End If
End If
End Sub

  • 1 Χρήστες που βρήκαν αυτό χρήσιμο
Ήταν χρήσιμη αυτήν την απάντηση;

Σχετικά Άρθρα

DSNless connection to MS Access

Here are some examples of DSNless connections to MS Access - this is highly recommended over...

What components are installed on the server?

ASPUpload (http://aspupload.com/)ASPJpeg (http://aspjpeg.com/) APSPDF (http://asp-pdf.com/)...

How to create a redirect (ASP)

How to create a redirect (ASP)... If you want to have your domain redirect to another page or...

ASP JPEG Example code

Please see the downloads section for example code

ASP Upload examples

Please see the downloads section for example code

Powered by WHMCompleteSolution