<% ' ************************************** 'Name: ASP function library for for an email delay queue ' File Name: email_valid_lib.asp ' Description: A set of functions for adding an email to a queue ' with a specified delay time and checking the queue ' for email to send ' Author: Simone Pia (simonepia@earthlink.net) ' Date Created: December 7, 2001 ' Last Modified: February 3, 2002, by Simone Pia ' Inputs: ' - as_emailAddr: where to send email that is added to the queue ' - ai_delayMin: delay time for sending email (in minutes) ' Outputs: ' - 1 on success ' - 0 on failure ' Table Dependencies: QUEUE_TBL ' Tables Updated: QUEUE_TBL ' Modification History: ' 2/3/02 SMP: implemented sendStudyPlanEmail function ' 24-FEB-2002 AG: added download function to send e-mails to people w/ expired software ' 2/27/02 SMP: replace hard-coded send email code with sendEmail function ' ************************************** ' ************************************** ' Include lib files ' ************************************** %> <% ' ************************************** ' TODO: move to Constants file ' ************************************** Dim consts_TOLL_FREE_EMAIL_SIGNATURE consts_TOLL_FREE_EMAIL_SIGNATURE = "Allen Resources, Inc." & chr(10) & "1-800-865-6911" & chr(10) & "401-667-0487, extension 104" & chr(10) & "http://www.allenresources.com" & chr(10) & "dianne@allenresources.com" Dim consti_TASK_QUEUE_TYPE_STUDY_PLAN Dim consti_TASK_QUEUE_DELAY_STUDY_PLAN Dim consti_TASK_QUEUE_TYPE_DOWNLOAD_EXPIRATION Dim consti_TASK_QUEUE_DELAY_DOWNLOAD_EXPIRATION 'AGG 24-JAN-2003 Dim consts_EMAIL_AUTO_3PHASE_SENDER Dim consts_TASK_QUEUE_DELAY_AUTO_3PHASE Dim consti_TASK_QUEUE_TYPE_AUTO_3PHASE Dim consti_EMAIL_AUTO_3PHASE_SUBJECT Dim consti_EMAIL_AUTO_3PHASE_MESSAGE consts_TASK_QUEUE_DELAY_AUTO_3PHASE = 720 ' 12 hours (default) consti_TASK_QUEUE_TYPE_AUTO_3PHASE = "3" ' TODO AGG: make this email one of they db-driven emails consts_EMAIL_AUTO_3PHASE_SENDER = "3phase@allenresources.com" consti_EMAIL_AUTO_3PHASE_SUBJECT = "3-Phase CFA Exam Review Strategy" consti_EMAIL_AUTO_3PHASE_MESSAGE = Chr(10) & _ "Thank you for your submission for the 3-Phase CFA Exam Review Strategy." & Chr(10) & _ Chr(10) & _ "Because of the increasing number of requests we received in the past" & _ "week, we are unable to call you directly within a reasonable timeframe." & _ "Therefore, to receive your 3-Phase Strategy immediately, call our" & _ "toll-free number at 1-800-865-6911 and press option 2. Ask to speak with" & _ "one of our CFA Exam Consultants about the 3-Phase Strategy." & Chr(10) & _ Chr(10) & _ "Please do not send an e-mail reply to this message, as any reply to this" & _ "e-mail will not be received by Allen Resources." & Chr(10) & _ Chr(10) & _ "Sincerely," & Chr(10) & _ Chr(10) & _ "Your CFA Exam Prep Team" & Chr(10) & _ "Allen Resources, Inc." & Chr(10) & _ "Toll-Free: 1-800-865-6911" consti_TASK_QUEUE_TYPE_STUDY_PLAN = "1" consti_TASK_QUEUE_DELAY_STUDY_PLAN = 720 ' 12 hours consti_TASK_QUEUE_TYPE_DOWNLOAD_EXPIRATION = "2" consti_TASK_QUEUE_DELAY_DOWNLOAD_EXPIRATION = 10080 ' 7 days ' ************************************** ' Declare page-scoped variables ' ************************************** Dim g_emailQueueLocked 'to lock the function emailQueuedStudyPlans ' so that it can't be called/used by multiple ' functions simultaneously ' ************************************** ' Initialize variables ' ************************************** g_emailQueueLocked = 0 '0=unlocked, 1=locked ' ************************************** ' Procedures begin here ' ************************************** ' ****************************************** ' Name: addToEmailTaskQueue ' AG 26-FEB-2002: changed name ' Description: adds a given email address to the queue, calculating ' the date/time that it should be sent as : ' the ldt_now time + the specified delay time ' Also checks and sends queued items ready to go ' Inputs: ' - as_emailAddr: where to send email that is added to the queue ' - ai_delayMin: delay time for sending email (in minutes) ' - (optional) as_firstName: first name of user ' - ai_QueueTaskType: type of queue item (study plan email, etc.) - added 26-FEB-2002 AG ' Outputs: ' - 1 on success ' - 0 on failure ' ****************************************** function addToEmailTaskQueue(as_emailAddr, as_firstName, ai_delayMin, ai_queueTaskType) Dim ldt_now, ldt_SendWhen, lb_emailSentFlag Dim ADODB_Connection, ls_SQL, recordSet addToEmailTaskQueue = 0 'returns 0 if failed 'calculate send date/time ldt_now = now() ldt_SendWhen = DateAdd("n", ai_delayMin, ldt_now) lb_emailSentFlag = 0 '0 = email has not been sent; 1 = email sent/"deleted" from queue 'add this to the email queue 'establish and open the connection to the db set ADODB_Connection = server.CreateObject("ADODB.Connection") ADODB_Connection.ConnectionString = consts_CONNECTION_STRING_QUEUE ADODB_Connection.Open 'NOTE: using db field MISC1 as an EMAIL_SENT_FLAG, MISC2 as first name, MISC3 as queue Type Select Case ai_queueTaskType Case consti_TASK_QUEUE_TYPE_STUDY_PLAN ls_SQL = "INSERT INTO QUEUE_TBL (TO_EMAIL, SEND_DATETIME, MISC1, MISC2, MISC3)" ls_SQL = ls_SQL & " VALUES ('" & as_emailAddr & "', '" & ldt_SendWhen & "', " & lb_emailSentFlag & ", '" & as_firstName & "','" & ai_queueTaskType & "')" Case consti_TASK_QUEUE_TYPE_AUTO_3PHASE ls_SQL = "INSERT INTO QUEUE_TBL (TO_EMAIL, SEND_DATETIME, MISC1, MISC2, MISC3)" ls_SQL = ls_SQL & " VALUES ('" & as_emailAddr & "', '" & ldt_SendWhen & "', " & lb_emailSentFlag & ", '" & as_firstName & "','" & ai_queueTaskType & "')" Case consti_TASK_QUEUE_TYPE_DOWNLOAD_EXPIRATION ls_SQL = "INSERT INTO QUEUE_TBL (TO_EMAIL, SEND_DATETIME, MISC1, MISC3)" ls_SQL = ls_SQL & " VALUES ('" & as_emailAddr & "', '" & ldt_SendWhen & "', " & lb_emailSentFlag & ", '" & ai_queueTaskType & "')" Case Else ' Do Nothing End Select ADODB_Connection.Execute(ls_SQL) ADODB_Connection.Close 'check the queue for emails that need to be sent AND send them emailQueuedMsgs addToEmailTaskQueue = 1 'returns 1 on success end function ' ****************************************** ' Name: emailQueuedMsgs ' AG 26-FEB-2002: changed name ' Description: Checks the email queue and sends any email whose send date/time ' is before now. Successfully mailed items are marked as sent ' This function "locks" itself so the queue can only be checked once at a time ' Inputs: ' - ai_QueueTaskType: type of queue item (study plan email, etc.) - added 26-FEB-2002 AG ' Outputs: ' - 1 on success (or if already locked) ' - 0 on failure ' ****************************************** function emailQueuedMsgs Dim ADODB_Connection, ls_SQL, recordSet Dim timeDiff, ldt_now, li_currentID emailQueuedMsgs = 0 'return value for failure if g_emailQueueLocked = 0 then g_emailQueueLocked = 1 'lock so no other functions can execute 'establish and open the connection to the db set ADODB_Connection = server.CreateObject("ADODB.Connection") ADODB_Connection.ConnectionString = consts_CONNECTION_STRING_QUEUE ADODB_Connection.Open 'query queue for emails that need to be sent ls_SQL = "SELECT * FROM QUEUE_TBL WHERE MISC1 = '0' AND SEND_DATETIME < now()" set recordSet = server.CreateObject("ADODB.Recordset") recordSet.open ls_SQL, ADODB_Connection Do While Not recordSet.eof Dim li_result li_result = 0 li_currentID = recordSet("ID") 'check the date/time on the unsent email Select Case recordSet("MISC3") Case consti_TASK_QUEUE_TYPE_STUDY_PLAN li_result = sendStudyPlanEmail(recordSet("TO_EMAIL"), recordSet("MISC2")) Case consti_TASK_QUEUE_TYPE_DOWNLOAD_EXPIRATION li_result = sendDownloadExpirationNotice(recordSet("TO_EMAIL")) Case consti_TASK_QUEUE_TYPE_AUTO_3PHASE li_result = send3PhaseAutoEmail(recordSet("TO_EMAIL"), recordSet("MISC2")) Case Else ' Do Nothing End Select If li_result = 1 Then 'delete this email from queue ls_SQL = "UPDATE QUEUE_TBL SET MISC1 = '1' WHERE ID = " & li_currentID ADODB_Connection.Execute(ls_SQL) End if recordSet.movenext Loop ADODB_Connection.Close g_emailQueueLocked = 0 'unlock to make this function available emailQueuedMsgs = 1 'return value for success else emailQueuedMsgs = 1 'return value for "locked" end if end function ' ****************************************** ' Name: send3PhaseAutoEmail ' Created: 24JAN2003 ' Description: Sends a 3-phase email asking people to call Allen Resources ' Inputs: as_toEmail-address to send email ' as_firstName- first name of person ' Outputs: 1 on success ' ****************************************** function send3PhaseAutoEmail(as_toEmail, as_firstName) Dim objMail Dim ls_message ls_message = "Dear " & as_firstName & " -" & Chr(10) & consti_EMAIL_AUTO_3PHASE_MESSAGE ' It's during business hours so send message now Set objMail = CreateObject("CDONTS.Newmail") objMail.MailFormat = 0 ' prevent unnecessary line breaks by sending object in MIME format objMail.Send consts_EMAIL_AUTO_3PHASE_SENDER, as_toEmail, consti_EMAIL_AUTO_3PHASE_SUBJECT, ls_message Set objMail = Nothing end function ' ****************************************** ' Name: sendStudyPlanEmail ' Description: Sends a study plan email ' Inputs: as_toEmail-address to send email ' Outputs: 1 on success ' ****************************************** function sendStudyPlanEmail(as_toEmail, as_firstName) 'AG 25-APR-2002: replace hard-coded send email code with sendEmail function sendEmail as_toEmail, consts_EMAIL_NAME_STUDY_PLAN, as_firstName, constas_EMAIL_TAGS_STUDY_PLAN,"DEFAULT" sendStudyPlanEmail = 1 end function ' ****************************************** ' Name: sendDownloadExpirationNotice ' Description: Sends msg to people who's software has expired ' Inputs: as_toEmail-address to send email ' Outputs: 1 on success ' ****************************************** function sendDownloadExpirationNotice(as_toEmail) Dim ls_from, ls_subject, ls_body Dim lo_objMail ls_from = consts_EMAIL_FORM_REPLY_TO ls_subject = "CFA Exam TestBank Questions" ls_body = "Thank you for downloading the free trial version of the TestBank Software. For the past 10 years, TestBank has helped more candidates pass than any other Study Tool." & chr(10) & chr(10) & "As you probably know already, your software will expire either today or tomorrow. However, we've put together an offer for you so you can utilize your TestBank Software for the 2002 CFA exam." & chr(10) & chr(10) & "To get your TestBank and use it on as many computers as you'd like, just go to" & chr(10) & "http://www.allenresources.com/orders/download" & chr(10) & "to order." & chr(10) & chr(10) & "If you want to save more, you may elect to purchase a Study System that includes TestBank (shipping is also free with all Study Systems)." & chr(10) & chr(10) & "Please let me know if you have any questions." & chr(10) & chr(10) & "Regards," & chr(10) & chr(10) & "Dianne Krawjewski" & chr(10) & consts_TOLL_FREE_EMAIL_SIGNATURE Set lo_objMail = CreateObject("CDONTS.Newmail") lo_objMail.MailFormat = 0 ' prevent unnecessary line breaks by sending object in MIME format lo_objMail.Send ls_from, as_toEmail, ls_subject, ls_body Set lo_objMail = Nothing sendDownloadExpirationNotice = 1 end function %>