You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
13KB

  1. <%
  2. '=======================================================================================================================
  3. ' Order-related outbound email: the "continue your order" link and the order-details
  4. ' confirmation sent after SubmitOrderDetails.
  5. '=======================================================================================================================
  6. Class OrderMailer_Class
  7. Public Sub SendContinuationEmail(email, token)
  8. Dim continueUrl
  9. continueUrl = Routes().AppURL & "order/continue?token=" & Server.URLEncode(token)
  10. Dim inner
  11. inner = "<div style=""color:#7c3bc0; font-weight:800; font-size:11px; letter-spacing:0.06em; text-transform:uppercase;"">Order Request Received</div>" & _
  12. "<h1 style=""color:#201a27; font-size:22px; margin:6px 0 12px; font-family:Arial, Helvetica, sans-serif;"">Continue your election materials order</h1>" & _
  13. "<p style=""color:#6d6574; font-size:13px; margin:0 0 20px;"">Click the button below to pick up where you left off.</p>" & _
  14. "<p style=""margin:0 0 20px;""><a href=""" & H(continueUrl) & """ style=""display:inline-block; background:#6529a0; color:#ffffff; font-weight:700; font-size:14px; padding:12px 28px; border-radius:10px; text-decoration:none;"">Continue your order</a></p>" & _
  15. "<p style=""color:#6d6574; font-size:12px; margin:0;"">Or copy and paste this link into your browser:<br /><a href=""" & H(continueUrl) & """ style=""color:#6529a0;"">" & H(continueUrl) & "</a></p>" & _
  16. "<p style=""color:#6d6574; font-size:12px; margin-top:16px;"">This link expires in " & H(GetAppSetting("OrderTokenExpirationHours")) & " hours and can only be used once.</p>"
  17. Dim mail : Set mail = NewConfiguredMail()
  18. mail.Subject = "Continue your Purple Envelope order"
  19. mail.IsBodyHTML = True
  20. mail.Body = EmailShell(inner)
  21. mail.AddRecipient "To", email
  22. mail.Send
  23. End Sub
  24. ' Best-effort: the order is already safely persisted by the time a caller reaches this -
  25. ' an SMTP hiccup here should not turn a successful submission into a failed one.
  26. Public Sub SendOrderDetailsEmail(order, model)
  27. On Error Resume Next
  28. Dim mail : Set mail = NewConfiguredMail()
  29. mail.Subject = "Your Purple Envelope order details - Jurisdiction " & order("JurisdictionNumber")
  30. mail.IsBodyHTML = True
  31. mail.Body = BuildOrderDetailsEmailBody(order, model)
  32. mail.AddRecipient "To", order("Email")
  33. Dim ccAddress, ccAddresses
  34. ccAddresses = OrderReceivedCcAddresses()
  35. For Each ccAddress In ccAddresses
  36. mail.AddRecipient "Cc", ccAddress
  37. Next
  38. mail.Send
  39. Err.Clear
  40. On Error GoTo 0
  41. End Sub
  42. '-------------------------------------------------------------------------------------------------------------------
  43. ' Private helpers
  44. '-------------------------------------------------------------------------------------------------------------------
  45. ' Staff addresses CC'd on every "order received" confirmation email.
  46. Private Function OrderReceivedCcAddresses()
  47. OrderReceivedCcAddresses = Array( _
  48. "natascham@kentcommunications.com", _
  49. "erickaw@kentcommunications.com", _
  50. "danielc@kentcommunications.com", _
  51. "katelyne@kentcommunications.com")
  52. End Function
  53. Private Function NewConfiguredMail()
  54. Dim smtpPort : smtpPort = GetAppSetting("SmtpPort")
  55. If Not IsNumeric(smtpPort) Then smtpPort = 25
  56. Dim mail : Set mail = CDOEmail()
  57. mail.SMTPServer = GetAppSetting("SmtpServer")
  58. mail.SMTPPort = CInt(smtpPort)
  59. mail.SMTPUsername = GetAppSetting("SmtpUsername")
  60. mail.SMTPPassword = GetAppSetting("SmtpPassword")
  61. mail.SMTPUseSSL = (LCase(GetAppSetting("SmtpUseSSL")) = "true")
  62. mail.From = GetAppSetting("SmtpFromAddress")
  63. Set NewConfiguredMail = mail
  64. End Function
  65. Private Function BuildOrderDetailsEmailBody(order, model)
  66. Dim html
  67. html = "<div style=""color:#7c3bc0; font-weight:800; font-size:11px; letter-spacing:0.06em; text-transform:uppercase;"">Order Received</div>" & _
  68. "<h1 style=""color:#201a27; font-size:22px; margin:6px 0 4px; font-family:Arial, Helvetica, sans-serif;"">Thanks! We've received your order details.</h1>" & _
  69. "<p style=""color:#6d6574; font-size:13px; margin:0 0 8px;"">Jurisdiction number <strong style=""color:#201a27;"">" & H(order("JurisdictionNumber")) & "</strong>" & _
  70. " &middot; submitted " & H(EmailDate(model.SubmittedAt)) & "</p>"
  71. html = html & EmailSection("Contact Information", _
  72. EmailRow("Contact Name", model.ContactName) & _
  73. EmailRow("Municipality", model.Municipality) & _
  74. EmailRow("Phone", model.Phone))
  75. If IsTrue(model.PurpleWantsQuote) Then
  76. html = html & EmailSection("Purple Ballot Envelopes", _
  77. EmailRow("Permanent ballot list count", model.PurplePermanentBallotListCount) & _
  78. EmailRow("Envelope stock", LabelEnvelopeStock(model.PurpleEnvelopeStock)) & _
  79. EmailRow("Print option", LabelPrintOption(model.PurplePrintOption)) & _
  80. EmailRow("Print style", LabelPrintStyle(model.PurplePrintStyle)) & _
  81. EmailRow("Color coding by", LabelColorCodingBy(model.PurpleColorCodingBy)) & _
  82. EmailRow("Number of precincts", model.PurplePrecinctCount) & _
  83. EmailRow("Colors requested", model.PurpleColorNames) & _
  84. EmailRow("Track with TrackMI Ballot", EmailYesNo(model.PurpleTrackMIBallot)) & _
  85. EmailRow("Extra envelopes requested", model.PurpleExtraEnvelopeQty))
  86. End If
  87. If Not IsNull(model.BlueWantsQuote) Then
  88. Dim blueProviderLine
  89. blueProviderLine = LabelPurpleBlueProvider(model.PurpleBlueProvider)
  90. If blueProviderLine = "Other" And Len(Trim(model.PurpleBlueProviderOther & "")) > 0 Then
  91. blueProviderLine = model.PurpleBlueProviderOther
  92. End If
  93. ' City/permit number are collected for an own-organization permit - a permit
  94. ' lookup can't be done from the nonprofit authorization code alone.
  95. Dim bluePermitLine
  96. bluePermitLine = ""
  97. If LabelPermitOwnership(model.BluePermitOwnership) = "My organization's permit" Then
  98. bluePermitLine = bluePermitLine & _
  99. EmailRow("City of permit holder", model.BluePermitCity) & _
  100. EmailRow("Permit number", model.BluePermitNumber)
  101. End If
  102. html = html & EmailSection("Blue AV Envelopes", _
  103. EmailRow("Purchasing blue envelopes from KCI", EmailYesNo(model.BlueWantsQuote)) & _
  104. EmailRow("Additional office copies", model.BlueWantsOfficeCopies) & _
  105. EmailRow("Additional office copies requested", model.BlueOfficeCopiesQty) & _
  106. EmailRow("Blue envelope provider", blueProviderLine) & _
  107. EmailRow("Print permit", EmailYesNo(model.BluePrintPermit)) & _
  108. EmailRow("Permit ownership", LabelPermitOwnership(model.BluePermitOwnership)) & _
  109. EmailRow("Confirmed nonprofit status with USPS", LabelNonprofitStatus(model.BlueHasNonprofitStatus)) & _
  110. bluePermitLine)
  111. End If
  112. If IsTrue(model.MailingWantsService) Then
  113. Dim mailingAuthCodeLine
  114. mailingAuthCodeLine = ""
  115. If CStr(model.MailingHasNonprofitStatus & "") = "Yes" Then
  116. If IsTrue(model.MailingNonprofitAuthCodeUnknown) Then
  117. mailingAuthCodeLine = EmailRow("Nonprofit authorization code", "Unknown - customer needs help")
  118. Else
  119. mailingAuthCodeLine = EmailRow("Nonprofit authorization code", model.MailingNonprofitAuthCode)
  120. End If
  121. End If
  122. html = html & EmailSection("Ballot Mailing Service", _
  123. EmailRow("Postage", LabelPostageOption(model.MailingPostageOption)) & _
  124. EmailRow("Nonprofit status with USPS", LabelNonprofitStatus(model.MailingHasNonprofitStatus)) & _
  125. mailingAuthCodeLine & _
  126. EmailRow("Estimated quantity", model.MailingEstimatedQuantity) & _
  127. EmailRow("Preferred pickup date", EmailDate(model.MailingPickupDate)))
  128. End If
  129. If NumOrZero(model.SecrecySleevesQty) > 0 Or NumOrZero(model.IVotedStickerRolls) > 0 Or NumOrZero(model.FutureVoterStickerRolls) > 0 Or Len(Trim(model.SpecialRequests & "")) > 0 Then
  130. html = html & EmailSection("Additional Election Items", _
  131. EmailRow("Secrecy sleeves (quantity)", model.SecrecySleevesQty) & _
  132. EmailRow("""I Voted"" stickers (rolls of 250)", model.IVotedStickerRolls) & _
  133. EmailRow("""Future Voter"" stickers (rolls of 500)", model.FutureVoterStickerRolls) & _
  134. EmailRow("Special requests", model.SpecialRequests))
  135. End If
  136. html = html & "<p style=""color:#6d6574; font-size:12px; margin-top:24px;"">Questions about this order? Just reply to this email.</p>"
  137. BuildOrderDetailsEmailBody = EmailShell(html)
  138. End Function
  139. ' Wraps inner body HTML in the same header/footer chrome used across the website - the
  140. ' navy KCI Election Printing bar (matching the site header/footer) and white content card.
  141. Private Function EmailShell(innerHtml)
  142. Dim logoUrl : logoUrl = Routes().AppURL & "images/KCI%20ELECTION%20printing%20(white).png"
  143. EmailShell = "<!doctype html><html><body style=""margin:0; padding:0; background:#faf7fd; font-family:Arial, Helvetica, sans-serif;"">" & _
  144. "<table role=""presentation"" width=""100%"" cellpadding=""0"" cellspacing=""0"" style=""background:#faf7fd; padding:24px 0;""><tr><td align=""center"">" & _
  145. "<table role=""presentation"" width=""600"" cellpadding=""0"" cellspacing=""0"" style=""background:#ffffff; border-radius:12px; overflow:hidden; box-shadow:0 4px 16px rgba(36,16,58,0.08);"">" & _
  146. "<tr><td style=""background:#254B74; padding:20px 32px; text-align:center;"">" & _
  147. "<img src=""" & H(logoUrl) & """ alt=""KCI Election Printing"" width=""160"" style=""display:block; margin:0 auto; height:auto; max-width:160px;"" />" & _
  148. "</td></tr>" & _
  149. "<tr><td style=""padding:32px;"">" & innerHtml & "</td></tr>" & _
  150. "<tr><td style=""background:#254B74; padding:20px 32px; text-align:center;"">" & _
  151. "<div style=""color:#ffffff; font-size:12px; font-weight:700;"">KCI Election Printing</div>" & _
  152. "<div style=""color:rgba(255,255,255,0.75); font-size:11px; margin-top:4px;"">616.957.2120 &middot; info@kentcommunications.com</div>" & _
  153. "</td></tr>" & _
  154. "</table></td></tr></table></body></html>"
  155. End Function
  156. Private Function EmailSection(sectionTitle, rowsHtml)
  157. If Len(rowsHtml) = 0 Then
  158. EmailSection = ""
  159. Else
  160. EmailSection = "<h2 style=""color:#4d1d78; font-size:14px; margin:24px 0 8px; padding-top:16px; border-top:1px solid #f0e7f8; font-family:Arial, Helvetica, sans-serif;"">" & _
  161. H(sectionTitle) & "</h2>" & _
  162. "<table role=""presentation"" width=""100%"" cellpadding=""0"" cellspacing=""0"">" & rowsHtml & "</table>"
  163. End If
  164. End Function
  165. Private Function EmailRow(label, value)
  166. If Len(Trim(value & "")) = 0 Then
  167. EmailRow = ""
  168. Else
  169. EmailRow = "<tr>" & _
  170. "<td style=""padding:6px 0; color:#6d6574; font-size:13px; width:45%; vertical-align:top;"">" & H(label) & "</td>" & _
  171. "<td style=""padding:6px 0; color:#201a27; font-size:13px; font-weight:600;"">" & H(value) & "</td>" & _
  172. "</tr>"
  173. End If
  174. End Function
  175. ' Null-safe boolean check for gating whole sections - a section's top-level "do you want
  176. ' this?" question isn't marked required client-side, so it may be missing (Null) rather
  177. ' than explicitly false.
  178. Private Function IsTrue(v)
  179. If IsNull(v) Then
  180. IsTrue = False
  181. Else
  182. IsTrue = CBool(v)
  183. End If
  184. End Function
  185. Private Function EmailYesNo(v)
  186. If IsNull(v) Then
  187. EmailYesNo = ""
  188. ElseIf CBool(v) Then
  189. EmailYesNo = "Yes"
  190. Else
  191. EmailYesNo = "No"
  192. End If
  193. End Function
  194. Private Function EmailDate(v)
  195. If IsNull(v) Then
  196. EmailDate = ""
  197. Else
  198. On Error Resume Next
  199. EmailDate = MonthName(Month(v)) & " " & Day(v) & ", " & Year(v)
  200. If Err.Number <> 0 Then EmailDate = ""
  201. Err.Clear
  202. On Error GoTo 0
  203. End If
  204. End Function
  205. Private Function NumOrZero(v)
  206. If IsNull(v) Or Not IsNumeric(v) Then
  207. NumOrZero = 0
  208. Else
  209. NumOrZero = CDbl(v)
  210. End If
  211. End Function
  212. End Class
  213. Dim OrderMailer_Class__Singleton
  214. Function OrderMailer()
  215. If IsEmpty(OrderMailer_Class__Singleton) Then
  216. Set OrderMailer_Class__Singleton = New OrderMailer_Class
  217. End If
  218. Set OrderMailer = OrderMailer_Class__Singleton
  219. End Function
  220. %>

Powered by TurnKey Linux.