Server Events/Client Scripts To create Email List

Tips submitted by ASPMaker users

Server Events/Client Scripts To create Email List

Postby rubenmiller » Wed Jul 13, 2011 5:38 am

I've been working on coding a server event/client script to send an email to a group. Below is the code i'm using:

' Email Sending event
Function Email_Sending(Email, Args)

If Page.PageID = "edit" Then ' if Edit page
Dim rs, nSubject, nSender, nRecipient
Set rs = Args("RsNew")

Dim rs2
Set rs2 = Conn.Execute("SELECT OfficerEmail AS coordinator FROM officers WHERE userlevel = 1")

IF CoordinatorView_Declined.Status.Currentvalue = "Pending" THEN '<--- sends email to individual who is offered the job
nSubject = "Off-Duty Job Offer"
nSender = rs2.fields("coordinator").value
Email.Content = "Location: " & Trim(rs("JobName"))_
& vbCrLf & "Date: " & rs("JobDate")_
& vbCrLf & "Start: " & rs("StartTime")_
& vbCrLf & "End: " & rs("EndTime")_
& vbCrLf & "Please Respond by: " & rs("Respondby")_
& vbCrLf & vbCrLf & "Respectfully,"_
& vbCrLf & "Off-Duty Job Coordinator"
Email.Subject = nSubject
Email.Sender = nSender
Email.Recipient = rs("OfficerEmail")
Email_Sending = True

ELSEIF CoordinatorView_Declined.Status.Currentvalue = "OpenBid" THEN '<--- Sends email to everyone who has asked to be notified of a new job on the openbid board
Dim rs3, sNotify
set rs3 = Conn.Execute("SELECT OfficerEmail FROM officers WHERE notify = 1")
do until rs3.EOF
sNotify = sNotify + rs3.fields("OfficerEmail").value + ";"
rs3.MoveNext
loop
rs3.close

nRecipient = sNotify
nSubject = "New Open Job Posting"
nSender = rs2.fields("coordinator").value
Email.Content = "Location: " & Trim(rs("JobName"))_
& vbCrLf & "Date: " & rs("JobDate")_
& vbCrLf & "Start: " & rs("StartTime")_
& vbCrLf & "End: " & rs("EndTime")
Email.Subject = nSubject
Email.Sender = nSender
Email.Recipient = nRecipient
Email_Sending = True

ELSEIF CoordinatorView_Declined.Status.Currentvalue = "Accepted" THEN '<--- Sends email to individual with accepted status
nSubject = "Accepted Off-Duty Job"
nSender = rs2.fields("coordinator").value
Email.Content = "You have been assigned the following off-duty job:"_
& vbCrLf & "Location: " & Trim(rs("JobName"))_
& vbCrLf & "Date: " & rs("JobDate")_
& vbCrLf & "Start: " & rs("StartTime")_
& vbCrLf & "End: " & rs("EndTime")_
& vbCrLf & "If you are unable to perfom this responsibility please post to the Open Job Board immediately"_
& vbCrLf & vbCrLf & "Respectfully,"_
& vbCrLf & "Off-Duty Job Coordinator"
Email.Subject = nSubject
Email.Sender = nSender
Email.Recipient = rs("OfficerEmail")
Email_Sending = True

ELSE
END IF

End IF

End Function

I'm still working on cleaning up the code. I have a few areas that could be streamlined to make it look better. It works great at this point. The only thing I will caution you on is that the order fo the events seems to be important. If the Email.Content statment is after the subject/sender/recipient it doesn't work. No idea why.

If you have any suggestions please post. I'm just learning how to write these codes.

Thanks for everyones help.
R Miller
rubenmiller
 

Re: Server Events/Client Scripts To create Email List

Postby rubenmiller » Thu Jul 14, 2011 11:12 pm

The first snippet of code I posted was from a view where someone has declined a job offer from the Coordinator. The coordinator can re-assign the job, send it to the open bid board or directly send it to someone who may have verbally accepted the postition.

From the open bid board the email_sending function needs to send a confirmation to the accepting officer, send a notice to the job coordinator that the job is filled and lastly send a notice to the posting officer that someone took the job.

Code:

' Email Sending event
Function Email_Sending(Email, Args)

If Page.PageID = "edit" Then ' if Edit page
Dim rs, nSubject, nSender, rs3
Set rs = Args("RsNew")
Set rs3 = Args("RsOld")
Dim rs2
Set rs2 = Conn.Execute("SELECT OfficerEmail AS coordinator FROM officers WHERE userlevel = 1")'<--there is only one coordinator in this app. If there are more then you would have to use a list like function to build a "To" group (see above)

IF Open_Jobs.Status.Currentvalue = "Accepted" THEN
nSubject = "Accepted Off Duty Job"
nSender = rs2.fields("coordinator").value
Email.Content = "You have accepted the following Off-Duty Job:"_
& vbCrLf & "Location: " & Trim(rs("JobName"))_
& vbCrLf & "Date: " & rs("JobDate")_
& vbCrLf & "Start: " & rs("StartTime")_
& vbCrLf & "End: " & rs("EndTime")_
& vbCrLf & "If you are unable to perfom this responsibility please post to the Open Job Board immediately"_
& vbCrLf & vbCrLf & "Respectfully,"_
& vbCrLf & "Off-Duty Job Coordinator"
Email.Subject = nSubject
Email.Sender = nSender
Email.Recipient = rs("OfficerEmail")
Email.Cc = nSender + ";" + rs3("OfficerEmail") '<-- this sends the Cc email to the coodinator and to the posting officer
Email_Sending = True
ELSE
END IF

End IF

End Function

Is you read the aspfn#.asp file in the cEmail (around line 85 in aspv8.1) you can see all of the strings that are available to change. Changing the values by setting them as Email.<string> you can customize the entire email with out changing the notify.txt file. I think it's much easier than having to edit the notify.txt file everytime. If the resulting email is in the form of the default notify.txt then that's an indication that there is an error with you custom email message. Thats how I determined the importance of the order of the strings in the code.

Please post any suggestions to make this better.
Ruben
rubenmiller
 


Return to User Submitted Tips (ASPMaker)