/coolpier_scripts/_handlers/Email_Handler.asp -- Check it out -- Help test !!!

B

Brynn

((the help test message is towards the bottom of the page ... ASPMail
part of this subroutine is untested as of yet))

((also, the subroutine itself is at the bottom of this post as well))

I have heard a lot on this group about people using their email
components ... well, I thought I would share my subroutine that will
handle Persits ASPEmail, ServerObjects ASPMail, and CDONTS

The subroutine looks like this ...

Sub cp_EmailHandler(cp_TheComponent, cp_SMTPHost, cp_From, cp_ToList,
cp_ReplyTo, cp_Subject, cp_Body, cp_Attachments)

--example--
call cp_EmailHandler("ASPEmail", "mail.yourdomain.com",
"(e-mail address removed)", "to,[email protected],Their
Name;cc,[email protected];bcc,[email protected]",
"(e-mail address removed)", "The subject text.", "The body text",
Server.MapPath("/yourAttachment.zip"))

The breakdown of subroutine ...

cp_TheComponent -- this can be either "ASPEmail", "CDONTS", or
"ASPMail"

cp_SMTPHost -- your smtp host ... "mail.yourdomain.com"

cp_From -- "(e-mail address removed),Your Name" ... name is optional ... you
can put just "(e-mail address removed)" without the comma or name.

cp_ToList -- This list is sendType - comma - email address - comma -
name ... and you can have multiple addresses here with different send
types ... the name is still optional ... to seperate multiple email
address use the semi-colon ... example ...
"to,[email protected],Brynn;to,[email protected];cc,[email protected];bcc,[email protected],Their
Name"

cp_ReplyTo -- "(e-mail address removed)" ... the email address ONLY ...
you may not use name ... if you want the same as the from ... just use
the same value/variable

cp_Subject -- "Plain text subject line!!!!"

cp_Body -- "Text of the body ... the body." ... this can also be html
formatted email ... for this, the first 6 characters must be < H T M L
without spaces and must stay CAPS... example ... "<HTML><a
href=""www.coolpier.com"">Coolpier.com</a></html>"
The subroutine will automatically notice the html tag and change the
format of the email to html in the headers

cp_Attachments = -- Server.MapPath("/yourfolder/yourfile.zip") ...
this will also allow more than one attachment with a comma seperator
like ...
Server.MapPath("/yourfolder/yourfile.zip") & "," &
Server.MapPath("/yourfolder/yourotherfile.zip")


ANYWAY ... the full subroutine example at the top uses ASPEmail
component ... if you change "ASPEmail" to "CDONTS" ... BAM ... it is
already working with CDONTS

HELP TEST -- could someone that has ASPMail on their server test this
subroutine against it ... it should work great ... but I haven't
installed it on mine yet ... and my current Host doesn't have it.

=============================================
Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
=============================================

Now the subroutine ...















<%
'// Just a handler for using CDONTs, ASPEmail, and ASPMail components
- example
Sub cp_EmailHandler(cp_TheComponent, cp_SMTPHost, cp_From, cp_ToList,
cp_ReplyTo, cp_Subject, cp_Body, cp_Attachments)
Dim cp_MailObj, cp_n, cp_i, cp_arr1, cp_arr2, cp_str1,
cp_str2, cp_str3: cp_str1="": cp_str2="": cp_str3=""



'// SET MAIL OBJECT TO COMPONENT -- ASPEmail, CDONTS, or
ASPMAIL
Select Case cp_TheComponent
Case "ASPEmail": Set cp_MailObj =
CreateObject("Persits.MailSender")
Case "CDONTS": Set cp_MailObj =
CreateObject("CDONTS.NewMail")
Case "ASPMail": Set cp_MailObj =
CreateObject("SMTPsvg.Mailer")
End Select
With cp_MailObj



'// cp_From -- (e-mail address removed),Your Name --or--
(e-mail address removed)
'// cp_ToList -- to,[email protected],Their
Name;to,[email protected];cc,[email protected],Name
'// -- notice the above string has
sendType,email@address,Name(optional)
'// -- sendType can be to, cc, or bcc *comma*
email@address *comma* Optional Name ...
'// then *semicolon* before the next one, but
not one at the end of the string
'// cp_ReplyTo -- email address only ... no name
Select Case cp_TheComponent
Case "ASPEmail" '// www.persits.com
'//from
.Host = cp_SMTPHost: cp_arr1 = Split(cp_From,
","): .From = cp_arr1(0): .FromName = cp_arr1(ubound(cp_arr1))
'//to
cp_arr1 = Split(cp_ToList, ";")
For cp_n = 0 to ubound(cp_arr1)
cp_arr2 = Split(cp_arr1(cp_n), ",")
Select Case cp_arr2(0)
Case "to": .AddAddress
cp_arr2(1), cp_arr2(ubound(cp_arr2))
Case "cc": .AddCC cp_arr2(1),
cp_arr2(ubound(cp_arr2))
Case "bcc": .AddBcc
cp_arr2(1), cp_arr2(ubound(cp_arr2))
End Select
Next
If Not cp_ReplyTo = "" Then .AddReplyTo
cp_ReplyTo

Case "CDONTS" '//
'//from
cp_arr1 = Split(cp_From, ","): .From =
cp_arr1(ubound(cp_arr1)) & "<" & cp_arr1(0) & ">"
'//to
cp_arr1 = Split(cp_ToList, ";")
For cp_n = 0 to ubound(cp_arr1)
cp_arr2 = Split(cp_arr1(cp_n), ",")
Select Case cp_arr2(0)
Case "to": cp_str1 = cp_str1 &
"," & cp_arr2(ubound(cp_arr2)) & "<" & cp_arr2(1) & ">"
Case "cc": cp_str2 = cp_str2 &
"," & cp_arr2(ubound(cp_arr2)) & "<" & cp_arr2(1) & ">"
Case "bcc": cp_str3 = cp_str3
& "," & cp_arr2(ubound(cp_arr2)) & "<" & cp_arr2(1) & ">"
End Select
Next
If Not cp_str1 = "" Then .To = Replace("##" &
cp_str1, "##,", "")
If Not cp_str2 = "" Then .Cc = Replace("##" &
cp_str2, "##,", "")
If Not cp_str3 = "" Then .Bcc = Replace("##" &
cp_str3, "##,", "")
If Not cp_ReplyTo = "" Then .Value("Reply-To")
= cp_ReplyTo

Case "ASPMail" '// www.serverobjects.com
'//from
.RemoteHost = cp_SMTPHost: cp_arr1 =
Split(cp_From, ","): .FromAddress = cp_arr1(0): .FromName =
cp_arr1(ubound(cp_arr1))
'//to
cp_arr1 = Split(cp_ToList, ";")
For cp_n = 0 to ubound(cp_arr1)
cp_arr2 = Split(cp_arr1(cp_n), ",")
Select Case cp_arr2(0)
Case "to": .AddRecipient
cp_arr2(ubound(cp_arr2)), cp_arr2(1)
Case "cc": .AddCC
cp_arr2(ubound(cp_arr2)), cp_arr2(1)
Case "bcc": .AddBCC
cp_arr2(ubound(cp_arr2)), cp_arr2(1)
End Select
Next
If Not cp_ReplyTo = "" Then .ReplyTo =
cp_ReplyTo

End Select



'// cp_Subject -- Plain text subject line.
'// cp_Body -- HTML or plain text. If HTML, the first 6
characters must be <HTML> ... in caps
'// cp_Attachments -- A comma delimited string containing full
path to files to be attached
Select Case cp_TheComponent
Case "ASPEmail"
.Subject = cp_Subject
.Body = cp_Body: If Left(cp_Body, 6) =
"<HTML>" Then .IsHTML = True
If Not cp_Attachments = "" Then
cp_arr1 = Split(cp_Attachments, ",")
For cp_n = 0 to ubound(cp_arr1)
.AddAttachment cp_arr1(cp_n)
Next
End If

Case "CDONTS"
.Subject = cp_Subject
.Body = cp_Body: If Left(cp_Body, 6) =
"<HTML>" Then: .BodyFormat = 0: .MailFormat = 0: End If
If Not cp_Attachments = "" Then
cp_arr1 = Split(cp_Attachments, ",")
For cp_n = 0 to ubound(cp_arr1)
.AttachFile cp_arr1(cp_n)
Next
End If

Case "ASPMail"
.Subject = cp_Subject
.BodyText = cp_Body: If Left(cp_Body, 6) =
"<HTML>" Then .ContentType = "text/html"
If Not cp_Attachments = "" Then
cp_arr1 = Split(cp_Attachments, ",")
For cp_n = 0 to ubound(cp_arr1)
.AddAttachment cp_arr1(cp_n)
Next
End If

End Select



'// SEND MESSAGE
Select Case cp_TheComponent
Case "ASPEmail": .Send
Case "CDONTS": .Send
Case "ASPMail": .SendMail
End Select



End With
Set cp_MailObj = Nothing
End Sub
%>
Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
 
B

Brynn

I did forget to put for the cp_ToList ... the send types are to, cc,
or bcc

Brynn


((the help test message is towards the bottom of the page ... ASPMail
part of this subroutine is untested as of yet))

((also, the subroutine itself is at the bottom of this post as well))

I have heard a lot on this group about people using their email
components ... well, I thought I would share my subroutine that will
handle Persits ASPEmail, ServerObjects ASPMail, and CDONTS

The subroutine looks like this ...

Sub cp_EmailHandler(cp_TheComponent, cp_SMTPHost, cp_From, cp_ToList,
cp_ReplyTo, cp_Subject, cp_Body, cp_Attachments)

--example--
call cp_EmailHandler("ASPEmail", "mail.yourdomain.com",
"(e-mail address removed)", "to,[email protected],Their
Name;cc,[email protected];bcc,[email protected]",
"(e-mail address removed)", "The subject text.", "The body text",
Server.MapPath("/yourAttachment.zip"))

The breakdown of subroutine ...

cp_TheComponent -- this can be either "ASPEmail", "CDONTS", or
"ASPMail"

cp_SMTPHost -- your smtp host ... "mail.yourdomain.com"

cp_From -- "(e-mail address removed),Your Name" ... name is optional ... you
can put just "(e-mail address removed)" without the comma or name.

cp_ToList -- This list is sendType - comma - email address - comma -
name ... and you can have multiple addresses here with different send
types ... the name is still optional ... to seperate multiple email
address use the semi-colon ... example ...
"to,[email protected],Brynn;to,[email protected];cc,[email protected];bcc,[email protected],Their
Name"

cp_ReplyTo -- "(e-mail address removed)" ... the email address ONLY ...
you may not use name ... if you want the same as the from ... just use
the same value/variable

cp_Subject -- "Plain text subject line!!!!"

cp_Body -- "Text of the body ... the body." ... this can also be html
formatted email ... for this, the first 6 characters must be < H T M L
href=""www.coolpier.com"">Coolpier.com</a></html>"
The subroutine will automatically notice the html tag and change the
format of the email to html in the headers

cp_Attachments = -- Server.MapPath("/yourfolder/yourfile.zip") ...
this will also allow more than one attachment with a comma seperator
like ...
Server.MapPath("/yourfolder/yourfile.zip") & "," &
Server.MapPath("/yourfolder/yourotherfile.zip")


ANYWAY ... the full subroutine example at the top uses ASPEmail
component ... if you change "ASPEmail" to "CDONTS" ... BAM ... it is
already working with CDONTS

HELP TEST -- could someone that has ASPMail on their server test this
subroutine against it ... it should work great ... but I haven't
installed it on mine yet ... and my current Host doesn't have it.

=============================================
Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
=============================================

Now the subroutine ...















<%
'// Just a handler for using CDONTs, ASPEmail, and ASPMail components
- example
Sub cp_EmailHandler(cp_TheComponent, cp_SMTPHost, cp_From, cp_ToList,
cp_ReplyTo, cp_Subject, cp_Body, cp_Attachments)
Dim cp_MailObj, cp_n, cp_i, cp_arr1, cp_arr2, cp_str1,
cp_str2, cp_str3: cp_str1="": cp_str2="": cp_str3=""



'// SET MAIL OBJECT TO COMPONENT -- ASPEmail, CDONTS, or
ASPMAIL
Select Case cp_TheComponent
Case "ASPEmail": Set cp_MailObj =
CreateObject("Persits.MailSender")
Case "CDONTS": Set cp_MailObj =
CreateObject("CDONTS.NewMail")
Case "ASPMail": Set cp_MailObj =
CreateObject("SMTPsvg.Mailer")
End Select
With cp_MailObj



'// cp_From -- (e-mail address removed),Your Name --or--
(e-mail address removed)
'// cp_ToList -- to,[email protected],Their
Name;to,[email protected];cc,[email protected],Name
'// -- notice the above string has
sendType,email@address,Name(optional)
'// -- sendType can be to, cc, or bcc *comma*
email@address *comma* Optional Name ...
'// then *semicolon* before the next one, but
not one at the end of the string
'// cp_ReplyTo -- email address only ... no name
Select Case cp_TheComponent
Case "ASPEmail" '// www.persits.com
'//from
.Host = cp_SMTPHost: cp_arr1 = Split(cp_From,
","): .From = cp_arr1(0): .FromName = cp_arr1(ubound(cp_arr1))
'//to
cp_arr1 = Split(cp_ToList, ";")
For cp_n = 0 to ubound(cp_arr1)
cp_arr2 = Split(cp_arr1(cp_n), ",")
Select Case cp_arr2(0)
Case "to": .AddAddress
cp_arr2(1), cp_arr2(ubound(cp_arr2))
Case "cc": .AddCC cp_arr2(1),
cp_arr2(ubound(cp_arr2))
Case "bcc": .AddBcc
cp_arr2(1), cp_arr2(ubound(cp_arr2))
End Select
Next
If Not cp_ReplyTo = "" Then .AddReplyTo
cp_ReplyTo

Case "CDONTS" '//
'//from
cp_arr1 = Split(cp_From, ","): .From =
cp_arr1(ubound(cp_arr1)) & "<" & cp_arr1(0) & ">"
'//to
cp_arr1 = Split(cp_ToList, ";")
For cp_n = 0 to ubound(cp_arr1)
cp_arr2 = Split(cp_arr1(cp_n), ",")
Select Case cp_arr2(0)
Case "to": cp_str1 = cp_str1 &
"," & cp_arr2(ubound(cp_arr2)) & "<" & cp_arr2(1) & ">"
Case "cc": cp_str2 = cp_str2 &
"," & cp_arr2(ubound(cp_arr2)) & "<" & cp_arr2(1) & ">"
Case "bcc": cp_str3 = cp_str3
& "," & cp_arr2(ubound(cp_arr2)) & "<" & cp_arr2(1) & ">"
End Select
Next
If Not cp_str1 = "" Then .To = Replace("##" &
cp_str1, "##,", "")
If Not cp_str2 = "" Then .Cc = Replace("##" &
cp_str2, "##,", "")
If Not cp_str3 = "" Then .Bcc = Replace("##" &
cp_str3, "##,", "")
If Not cp_ReplyTo = "" Then .Value("Reply-To")
= cp_ReplyTo

Case "ASPMail" '// www.serverobjects.com
'//from
.RemoteHost = cp_SMTPHost: cp_arr1 =
Split(cp_From, ","): .FromAddress = cp_arr1(0): .FromName =
cp_arr1(ubound(cp_arr1))
'//to
cp_arr1 = Split(cp_ToList, ";")
For cp_n = 0 to ubound(cp_arr1)
cp_arr2 = Split(cp_arr1(cp_n), ",")
Select Case cp_arr2(0)
Case "to": .AddRecipient
cp_arr2(ubound(cp_arr2)), cp_arr2(1)
Case "cc": .AddCC
cp_arr2(ubound(cp_arr2)), cp_arr2(1)
Case "bcc": .AddBCC
cp_arr2(ubound(cp_arr2)), cp_arr2(1)
End Select
Next
If Not cp_ReplyTo = "" Then .ReplyTo =
cp_ReplyTo

End Select



'// cp_Subject -- Plain text subject line.
'// cp_Body -- HTML or plain text. If HTML, the first 6
characters must be <HTML> ... in caps
'// cp_Attachments -- A comma delimited string containing full
path to files to be attached
Select Case cp_TheComponent
Case "ASPEmail"
.Subject = cp_Subject
.Body = cp_Body: If Left(cp_Body, 6) =
"<HTML>" Then .IsHTML = True
If Not cp_Attachments = "" Then
cp_arr1 = Split(cp_Attachments, ",")
For cp_n = 0 to ubound(cp_arr1)
.AddAttachment cp_arr1(cp_n)
Next
End If

Case "CDONTS"
.Subject = cp_Subject
.Body = cp_Body: If Left(cp_Body, 6) =
"<HTML>" Then: .BodyFormat = 0: .MailFormat = 0: End If
If Not cp_Attachments = "" Then
cp_arr1 = Split(cp_Attachments, ",")
For cp_n = 0 to ubound(cp_arr1)
.AttachFile cp_arr1(cp_n)
Next
End If

Case "ASPMail"
.Subject = cp_Subject
.BodyText = cp_Body: If Left(cp_Body, 6) =
"<HTML>" Then .ContentType = "text/html"
If Not cp_Attachments = "" Then
cp_arr1 = Split(cp_Attachments, ",")
For cp_n = 0 to ubound(cp_arr1)
.AddAttachment cp_arr1(cp_n)
Next
End If

End Select



'// SEND MESSAGE
Select Case cp_TheComponent
Case "ASPEmail": .Send
Case "CDONTS": .Send
Case "ASPMail": .SendMail
End Select



End With
Set cp_MailObj = Nothing
End Sub
%>
Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!

Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top