-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_mailer.cfm
133 lines (130 loc) · 3.66 KB
/
_mailer.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<cfsilent>
<!---
Run Rate is the number of seconds between refresh. To
optimize this make this setting about 2 seconds longer
than the ColdFusion Server's mail spool fetch rate.
Otherwise mail will pile up in the spooler and partially
defeat the purpose of trickling out the mail
--->
<cfset variables.RunRate=5>
<!---
Query Run is the number of query rows (email addresses)
that will be processed on each execution of this template
--->
<cfset variables.QueryRun=5>
<!---
pull the ID field so we can get a record count.
--->
<cfquery
datasource="#dsource#" dbtype="ODBC" username="#uname#" password="#pword#"
name="MailList">
SELECT
mailer.ID
FROM mailer
WHERE
mailer.EmailAddr IS NOT NULL
ORDER BY
mailer.ID ASC
</cfquery>
<!---
Do some stuff to prevent page caching, which was found to
be a problem on some client browsers
--->
<cfheader
name="Expires"
value="Sun, 06 Nov 1994 08:49:37 GMT">
<cfheader
name="Pragma"
value="no-cache">
<cfheader
name="cache-control"
value="no-cache, no-store, must-revalidate">
</cfsilent>
<!---
Are we there yet?
--->
<cfif MailList.RecordCount lt 1>
<!---
yes. Inform the user
--->
<html><head><title>FINISHED</title></head>
<h1>All Done</h1>
<b>Close this browser window!</b>
<p><b>Do NOT press your BACK button</b> to leave.</p>
</body></html>
<cfelse>
<!---
display the "in-progress" page
--->
<html>
<cfoutput>
<!---
This next line re-runs the template automatically at the run rate.
Note the UUID inserted into the url. This is another part of ensuring
the browser doesn't cache this page.
--->
<meta
http-equiv="REFRESH"
content="#variables.RunRate#;URL=#cgi.script_name#
?UniqueURL=#UrlEncodedFormat(CreateUUID())#">
</cfoutput>
<head><title>Low Volume Mass Mailer with Failover</title></head>
<!---
Send the actual mail.
--->
<cfloop
query="MailList"
startrow="1"
endrow="#variables.QueryRun#">
<cfquery name="ThisEmail" datasource="#dsource#" dbtype="ODBC" username="#uname#" password="#pword#">
SELECT
mailer.EmailAddr,
mailer.EmailMsg,
mailer.EmailType,
mailer.EmailServer,
mailer.EmailSubject,
mailer.EmailFrom
FROM mailer
WHERE
mailer.ID=
<cfqueryparam
cfsqltype="CF_SQL_NUMERIC"
value="#MailList.ID#">
</cfquery>
<cfmail
to="[email protected]"
from="#ThisEmail.EmailFrom#"
subject="#ThisEmail.EmailSubject#"
server="#ThisEmail.EmailServer#"
username="[email protected]"
password="re3objec"
type="#ThisEmail.EmailType#">
<cfmailparam
name="Message-ID"
value="<#CreateUUID()#@#ThisEmail.EmailServer#>">
#ThisEmail.EmailMsg#
</cfmail>
<cfquery
datasource="#request.myDSN#">
DELETE FROM mailer
WHERE
mailer.ID=
<cfqueryparam
cfsqltype="CF_SQL_NUMERIC"
value="#MailList.ID#">
</cfquery>
</cfloop>
<!---
give the user a visual cue as to where the operation is at the moment.
You can get qite fancy here with pretty html and time-to-completion
calculations based on your record count, refresh rate etc.
--->
<cfset variables.LeftToGo=MailList.RecordCount-variables.QueryRun>
<cfoutput>
<p><b>Total left to send: #variables.LeftToGo#</b>.</p>
<p>Each run is #variables.RunRate# seconds apart.</p>
</cfoutput>
<p>Leave this system alone and wait for this job to complete.</p>
<p>When it finishes, you will be notified.</p>
</body></html>
</cfif>