pr3mium
Posts: 31
|
Posted: 02/17/2004, 10:55 PM |
|
I added the following sub to the end of common.asp
In order to use the sub for sending e-mail to several addresses (querying from some kind of a mailing list table, etc), all the addresses should be in a string separated by semicolon.
The sub uses the first address on TO line and the rest in CC.
Public Sub SendEmail(sTo, sSubject, sBody)
on error resume next
Dim mail
Dim i, semiCount, adr_count, sTo_Array
Dim TOstring, CCstring
Set mail = server.CreateObject("Persits.MailSender")
i = 0
mail.host = "hostname"
mail.port = "25"
mail.from = "fromname@domain.com"
mail.fromName = "fromname"
Mail.Subject = sSubject
Mail.Body = sBody
Mail.IsHTML = True
CCstring = ""
If instr(sTo,";") > 1 Then
sTo_array = Split(sTo,";")
adr_count = UBound(sTo_array)
For i = 1 to adr_count
If i <> adr_count Then
CCstring = CCstring & sTo_array(i) & ", "
else
CCstring = CCstring & sTo_array(i)
End If
Next
TOstring = sTo_array(0)
else
TOstring = sTo
End If
mail.addAddress TOstring
mail.addCC CCstring
Mail.Send
End Sub
Within the project I use call SendEmail(To,Subject,Body) anywhere I need to send e-mail.
Hope to hear some comments and suggestions - I'm not a programmer, so may be I did something abnormal, but it does work for me.
|
|
|
peterr
Posts: 5971
|
Posted: 02/19/2004, 5:31 PM |
|
pr3mium,
I didn't analyze in detail or test your code, but your approach looks good - defininig functions at the end of Common.asp and using them in the individual pages later.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
jayme
|
Posted: 03/08/2004, 6:34 AM |
|
I've been trying to do this forever and was unsuccessful at trying to reference multiple email address to send to multiple people based upon my CCDLookup function.
Looks like you solved that problem.
Did you put the call SendEmail(To,Subject,Body) on an on-click event for a form submit button? That's what I'd like to try.
Please let me know. Great work and thanks for sharing.
Jayme
|
|
|
pr3mium
Posts: 31
|
Posted: 03/08/2004, 6:50 AM |
|
Well, I've used this method for notifying a list of people of data changes in our employee directory. So, I used call SendEmail in AfterInsert and After Update events. But you may use it anywhere. I believe any event can call the Sub from the common.asp.
Glad you liked it
|
|
|
Jayme
|
Posted: 03/08/2004, 7:19 AM |
|
Forgot to mention that I am using ASP code. I could not make this work with the code for Mailer.AddAddress due to the looping. Always looking for an alternative way of getting to this query to get the recipient email addresses based upon the criteria I set forth. Any clues?
Dim Mailer
Set Mailer = Server.CreateObject("Persits.MailSender")
Mailer.From = CCDLookUp("email_sec", "tbl_users", "user_id=" & CCToSQL(CCGetUserID,"Integer"), DBTRACS)
Mailer.FromName = CCDLookUp("last_name", "tbl_users", "user_id=" & CCToSQL(CCGetUserID,"Integer"), DBTRACS)
Mailer.AddAddress CCDLookUp("email_sec", "qry_approver_role", "clearance_id=" & CCToSQL(qry_clearancefortrip.clearance_id.Value,"Integer"), DBTRACS)
Mailer.Host = "eccsexchange"
Mailer.IsHTML = True
Mailer.Subject = "New visit request for you"
Mailer.Body = "The following task was submitted:<br><br>" &_
"Travel Request No.: " & tbl_travelrequests.travelrequest_no.value
'CCDLookUp("travelrequest_no", "tbl_travelrequests", "travelrequest_id=" &_
'DBTRACS.ToSQL(tbl_travelrequests.travelrequest_id.value, "Integer"), DBTRACS)
Mailer.Send
set Mailer = Nothing
|
|
|
|