Emailer Function:
Send email using either CDOSYS, JMail, CDONTS or AspEmail components
Description:
Emailer Function send email using either CDOSYS, JMail, CDONTS or AspEmail components. Returns True for email correctly sent or False if any error.
Syntax:
Emailer(sSubject, sEmailBody, sFormat, strToEmail, strToEmailBCC, strFromEmail, strFromName, strServer)
Details:
'--- Input arguments: '--- sMailObject = Used component, either CDOSYS, JMail, CDONTS or AspEmail '--- sSubject = The subject of the e-mail '--- sEmailBody = The main HTML or TXT body of the e-mail '--- sFormat = Ether HTML for an HTML email body or null ("") for text only body '--- strToEmail = Who the e-mail is sent to '--- strToEmailBCC = The Bcc addressee of the e-mail '--- strFromEmail = Who the e-mail is from '--- strFromName = Name of who the e-mail is from '--- strServer = Out going SMTP mail server address
Example:
<%
Response.Write Emailer("Email Subject", "Email Body", "HTML", "test@test.com, ", "me@me.com", "My name", "localhost:25") '--- returns: True
%>
ASP Source Code:
<%
Sub Emailer(sSubject, sEmailBody, sFormat, strToEmail, strToEmailBCC, strFromEmail, strFromName, sMailObject, strServer) Dim bHTMLemail If UCase(sFormat) = "HTML" Then bHTMLEmail = True
On Error Resume Next Select Case UCase(sMailObject) '-------------------- Case "CDOSYS" DIM iMsg, Flds, iConf Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") Set Flds = iConf.Fields Flds("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True Flds.Update With iMsg Set .Configuration = iConf .To = strToEmail If strToEmailBCC <> "" Then .Bcc = strToEmailBCC End if .From = strFromEmail .Sender = strFromName .Subject = sSubject If bHTMLEmail Then .HTMLBody = sEmailBody Else .TextBody = sEmailBody End if .Send if Err.Number <> 0 then bSentEmail = False Else bSentEmail = True End If End With Set iMsg = Nothing Set iConf = Nothing Set Flds = Nothing '-------------------- Case "JMAIL" Dim JMail Set JMail = Server.CreateObject("JMail.SMTPMail") With JMail .ServerAddress = strServer .Sender = strFromEmail .Subject = sSubject .AddRecipient strToEmail If len(strToEmailBCC) > 0 Then .AddRecipientBcc strToEmailBCC End if If bHTMLEmail Then .ContentType = "text/html" .Body = sEmailBody Else .ContentType = "text/plain" .Body = sEmailBody End if .Priority = 1 .AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR") .Execute if Err.Number <> 0 then bSentEmail = False Else bSentEmail = True End If End With Set JMail = nothing '-------------------- Case "CDONTS" Dim objMail Set objMail = CreateObject("CDONTS.NewMail") With obJMail .From = strFromEmail .To = strToEmail .Bcc = strToEmailBCC .Subject = sSubject .Body = sEmailBody .Send if Err.Number <> 0 then bSentEmail = False Else bSentEmail = True End If End With Set objMail = nothing '-------------------- Case "ASPEMAIL" Dim objAspEmail Set objAspEmail = Server.CreateObject("Persits.MailSender") With objAspEmail .Host = strServer .Port = 25 '--- Out going mail server port .From = strFromEmail .AddAddress strToEmail .AddBcc strToEmailBCC .Subject = sSubject If bHTMLEmail Then .IsHTML = True .Body = sEmailBody Else .IsHTML = False .Body = sEmailBody End if If NOT serveraddress = "" Then .Send if Err.Number <> 0 then bSentEmail = False Else bSentEmail = True End If End With Set objAspEmail = Nothing End Select On Error Goto 0 Emailer = bSentEmail End Sub '--- Emailer
%>
|