Filed under:

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



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read

Language: