Classic ASP send Mail function with various mail components

I like to share my old code that i have used for the send email in classic ASP. This function supports
persitsaspmail, jmail, “jmailhtml, serverobjectsaspmail1, serverobjectsaspmail2, CDONTS, aspsmartmail

way to use it

fromName=”myname”

senderEmail =’test@test.com’

toEmail = ‘to@to.com’

Subject=’this is test’

message=’this is message’

pEmailComponent=’jmail’

Call sendmail(fromName,senderEmail,toEmail,Subject,message)

Code below:

<%
Function sendMail(fromName, from, rcpt, subject, body)

pEmailComponent=lcase(pEmailComponent)

on error resume next

if pEmailComponent=”persitsaspmail” then

set mail = server.CreateObject(“Persits.MailSender”)

‘ change with your smtp server

mail.IsHTML = false ‘ set to true if you want to send HTML emails
mail.Host = pSmtpServer
mail.From = from
mail.FromName = fromName
mail.AddAddress rcpt
mail.AddReplyTo from
mail.Subject = subject
mail.Body = body

on error resume next

mail.Send

end if

if pEmailComponent=”jmail” then

set mail = server.CreateOBject( “JMail.Message” )
mail.Logging = true
mail.silent = true
mail.From = from
mail.FromName = fromName
mail.Subject = subject

mail.AddRecipient rcpt

‘mail.MailServerUserName = strUser
‘mail.MailServerPassWord = strPassword

mail.Body = body

on error resume next

mail.send(pSmtpServer)

end if

if pEmailComponent=”jmailhtml” then

set mail = server.CreateOBject( “JMail.Message” )
mail.Logging = true
mail.silent = true
mail.From = from
mail.FromName = fromName
mail.Subject = subject

mail.AddRecipient rcpt

‘ if the client cannot read HTML
mail.Body = body

‘ HTML
mail.HTMLBody = “<HTML><BODY><font color=””red””>” &pCompany& “</font><br>”
mail.appendHTML “<img src=””http://&#8221; & pStoreLocation & “/store/images/” &pCompanyLogo& “””>”
mail.appendHTML “<br><br>” &body& “</BODY></HTML>”

on error resume next

mail.send(pSmtpServer)

end if

if pEmailComponent=”serverobjectsaspmail1″ then

set mail = Server.CreateObject(“SMTPsvg.mail”)

mail.RemoteHost = pSmtpServer

mail.FromName = fromName
mail.FromAddress = from
mail.AddRecipient rcpt, rcpt
mail.Subject = subject
mail.BodyText = body

on error resume next

mail.SendMail

end if

if pEmailComponent=”serverobjectsaspmail2″ then

set mail = Server.CreateObject(“SMTPsvg.Mailer”)

mail.RemoteHost = pSmtpServer

mail.FromName = fromName
mail.FromAddress = from
mail.AddRecipient rcpt, rcpt
mail.Subject = subject
mail.BodyText = body

on error resume next

mail.SendMail

end if
if pEmailComponent=”cdonts” then

Set mail = Server.CreateObject (“CDONTS.NewMail”)

mail.BodyFormat = 1
mail.MailFormat = 0

on error resume next

mail.Send from, rcpt, subject, body

end if

if pEmailComponent=”cdontshtml” then

dim mail
set mail = Server.CreateObject(“CDONTS.NewMail”)

HTML = “”
HTML = HTML & “<HTML>”
HTML = HTML & “<HEAD>”
HTML = HTML & “<TITLE>” &pCompany& “</TITLE>”
HTML = HTML & “</HEAD>”
HTML = HTML & “<BODY bgcolor=””lightyellow””>”
HTML = HTML & “<TABLE cellpadding=””4″”>”
HTML = HTML & “<TR><TH><FONT color=””darkblue”” SIZE=””4″”>”
HTML = HTML & subject&”</FONT></TH></TR>”
HTML = HTML & “<TR><TD>”
HTML = HTML & body
HTML = HTML & “</FONT></TD></TR></TABLE><BR><BR>”
HTML = HTML & “</BODY>”
HTML = HTML & “</HTML>”

mail.From = from
mail.Subject = subject
mail.To = rcpt

‘ HTML format
mail.BodyFormat = 0
mail.MailFormat = 0
mail.Body = HTML
mail.Send

set mail = nothing

end if
if pEmailComponent=”bamboosmtp” then

set mail = Server.CreateObject(“Bamboo.SMTP”)
mail.Server = pSmtpServer
mail.Rcpt = rcpt
mail.From = from
mail.FromName = fromName
mail.Subject = subject
mail.Message = body

on error resume next

mail.Send

set mail = nothing

end if

if pEmailComponent=”ocxmail” then
set mail = Server.CreateObject(“ASPMAIL.ASPMailCtrl.1″)

on error resume next

mail.SendMail pSmtpServer, rcpt, from, subject, body

end if

if pEmailComponent=”dundasmail” then
dim objMailer
set objEmail = Server.CreateObject(“Dundas.Mailer”)
objEmail.TOs.Add rcpt
objEmail.FromAddress = from
objEmail.Subject = subject
objEmail.SMTPRelayServers.Add pSmtpServer
objEmail.Body = body
objEmail.SendMail
Set objEmail = Nothing
end if

if pEmailComponent=”aspsmartmail” then
dim mySmartMail
set mySmartMail = Server.CreateObject(“aspSmartMail.SmartMail”)
‘ change with your smtp server
mySmartMail.Server = pSmtpServer
mySmartMail.SenderName = fromName
mySmartMail.SenderAddress = from
‘mySmartMail.Recipients.Add receipt,receipt name
mySmartMail.Recipients.Add rcpt,””
mySmartMail.Subject = subject
mySmartMail.Body = body
mySmartMail.SendMail
set mySmartMail =Nothing

end if

if err <> 0 and pDebugEmail =”-1″ then
%> <html>
<br><br>
Error while sending email: <%=Err.Description%>.
<hr>
<br>From : <%=from%>
<br>To : <%=rcpt%>
<br>Subject : <%=subject%>
<br>Body : <%=body%></html><%
end if

end Function
%>

this is very old code, if you have any questions or suggestion let me know from the comments below.

if you are looking for some help in classic ASP let me know from the comments, i will try to reply when time permits.

thanks.