Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

215 lines
11KB

  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 mail : Set mail = NewConfiguredMail()
  11. mail.Subject = "Continue your Purple Envelope order"
  12. mail.IsBodyHTML = True
  13. mail.Body = "<p>Click the link below to continue your order:</p>" & _
  14. "<p><a href=""" & H(continueUrl) & """>" & H(continueUrl) & "</a></p>" & _
  15. "<p>This link expires in " & H(GetAppSetting("OrderTokenExpirationHours")) & _
  16. " hours and can only be used once.</p>"
  17. mail.AddRecipient "To", email
  18. mail.Send
  19. End Sub
  20. ' Best-effort: the order is already safely persisted by the time a caller reaches this -
  21. ' an SMTP hiccup here should not turn a successful submission into a failed one.
  22. Public Sub SendOrderDetailsEmail(order, model)
  23. On Error Resume Next
  24. Dim mail : Set mail = NewConfiguredMail()
  25. mail.Subject = "Your Purple Envelope order details - Jurisdiction " & order("JurisdictionNumber")
  26. mail.IsBodyHTML = True
  27. mail.Body = BuildOrderDetailsEmailBody(order, model)
  28. mail.AddRecipient "To", order("Email")
  29. mail.Send
  30. Err.Clear
  31. On Error GoTo 0
  32. End Sub
  33. '-------------------------------------------------------------------------------------------------------------------
  34. ' Private helpers
  35. '-------------------------------------------------------------------------------------------------------------------
  36. Private Function NewConfiguredMail()
  37. Dim smtpPort : smtpPort = GetAppSetting("SmtpPort")
  38. If Not IsNumeric(smtpPort) Then smtpPort = 25
  39. Dim mail : Set mail = CDOEmail()
  40. mail.SMTPServer = GetAppSetting("SmtpServer")
  41. mail.SMTPPort = CInt(smtpPort)
  42. mail.SMTPUsername = GetAppSetting("SmtpUsername")
  43. mail.SMTPPassword = GetAppSetting("SmtpPassword")
  44. mail.SMTPUseSSL = (LCase(GetAppSetting("SmtpUseSSL")) = "true")
  45. mail.From = GetAppSetting("SmtpFromAddress")
  46. Set NewConfiguredMail = mail
  47. End Function
  48. Private Function BuildOrderDetailsEmailBody(order, model)
  49. Dim html
  50. html = "<!doctype html><html><body style=""margin:0; padding:0; background:#faf7fd; font-family:Arial, Helvetica, sans-serif;"">" & _
  51. "<table role=""presentation"" width=""100%"" cellpadding=""0"" cellspacing=""0"" style=""background:#faf7fd; padding:24px 0;""><tr><td align=""center"">" & _
  52. "<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);"">" & _
  53. "<tr><td style=""background:#24103a; padding:24px 32px;"">" & _
  54. "<span style=""color:#ffffff; font-weight:700; font-size:18px;"">KCI Purple Envelope Order Confirmation</span>" & _
  55. "</td></tr>" & _
  56. "<tr><td style=""padding:32px;"">" & _
  57. "<div style=""color:#7c3bc0; font-weight:800; font-size:11px; letter-spacing:0.06em; text-transform:uppercase;"">Order Received</div>" & _
  58. "<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>" & _
  59. "<p style=""color:#6d6574; font-size:13px; margin:0 0 8px;"">Jurisdiction number <strong style=""color:#201a27;"">" & H(order("JurisdictionNumber")) & "</strong>" & _
  60. " &middot; submitted " & H(EmailDate(model.SubmittedAt)) & "</p>"
  61. html = html & EmailSection("Contact Information", _
  62. EmailRow("Contact Name", model.ContactName) & _
  63. EmailRow("Municipality", model.Municipality) & _
  64. EmailRow("Phone", model.Phone))
  65. If IsTrue(model.PurpleWantsQuote) Then
  66. Dim purpleBlueProviderLine
  67. purpleBlueProviderLine = LabelPurpleBlueProvider(model.PurpleBlueProvider)
  68. If purpleBlueProviderLine = "Other" And Len(Trim(model.PurpleBlueProviderOther & "")) > 0 Then
  69. purpleBlueProviderLine = model.PurpleBlueProviderOther
  70. End If
  71. html = html & EmailSection("Purple Ballot Envelopes", _
  72. EmailRow("Envelope stock", LabelEnvelopeStock(model.PurpleEnvelopeStock)) & _
  73. EmailRow("Print option", LabelPrintOption(model.PurplePrintOption)) & _
  74. EmailRow("Also wants KCI blue envelopes", EmailYesNo(model.PurpleWantsBlueEnvelopes)) & _
  75. EmailRow("Blue envelope provider", purpleBlueProviderLine) & _
  76. EmailRow("Print style", LabelPrintStyle(model.PurplePrintStyle)) & _
  77. EmailRow("Color coding by", LabelColorCodingBy(model.PurpleColorCodingBy)) & _
  78. EmailRow("Number of precincts", model.PurplePrecinctCount) & _
  79. EmailRow("Colors requested", model.PurpleColorNames) & _
  80. EmailRow("Track with TrackMI Ballot", EmailYesNo(model.PurpleTrackMIBallot)) & _
  81. EmailRow("Extra envelopes requested", model.PurpleExtraEnvelopeQty))
  82. End If
  83. If IsTrue(model.BlueWantsQuote) Then
  84. ' City/permit number are always collected for an own-organization permit - a
  85. ' permit lookup can't be done from the nonprofit authorization code alone, so
  86. ' that code is additional information when nonprofit status is Yes, not a
  87. ' replacement for city/permit number.
  88. Dim bluePermitLine
  89. bluePermitLine = ""
  90. If LabelPermitOwnership(model.BluePermitOwnership) = "My organization's permit" Then
  91. bluePermitLine = EmailRow("City of permit holder", model.BluePermitCity) & _
  92. EmailRow("Permit number", model.BluePermitNumber)
  93. If IsTrue(model.BlueHasNonprofitStatus) Then
  94. bluePermitLine = bluePermitLine & EmailRow("Nonprofit authorization code", model.BlueNonprofitAuthCode)
  95. End If
  96. End If
  97. html = html & EmailSection("Blue AV Envelopes", _
  98. EmailRow("Print permit", EmailYesNo(model.BluePrintPermit)) & _
  99. EmailRow("Permit ownership", LabelPermitOwnership(model.BluePermitOwnership)) & _
  100. EmailRow("Confirmed nonprofit status with USPS", EmailYesNo(model.BlueHasNonprofitStatus)) & _
  101. bluePermitLine)
  102. End If
  103. If IsTrue(model.MailingWantsService) Then
  104. html = html & EmailSection("Ballot Mailing Service", _
  105. EmailRow("Postage", LabelPostageOption(model.MailingPostageOption)) & _
  106. EmailRow("Nonprofit status with USPS", LabelNonprofitStatus(model.MailingHasNonprofitStatus)) & _
  107. EmailRow("Estimated quantity", model.MailingEstimatedQuantity) & _
  108. EmailRow("Preferred pickup date", EmailDate(model.MailingPickupDate)))
  109. End If
  110. If NumOrZero(model.SecrecySleevesQty) > 0 Or NumOrZero(model.IVotedStickerRolls) > 0 Or NumOrZero(model.FutureVoterStickerRolls) > 0 Or Len(Trim(model.SpecialRequests & "")) > 0 Then
  111. html = html & EmailSection("Additional Election Items", _
  112. EmailRow("Secrecy sleeves (quantity)", model.SecrecySleevesQty) & _
  113. EmailRow("""I Voted"" stickers (rolls of 250)", model.IVotedStickerRolls) & _
  114. EmailRow("""Future Voter"" stickers (rolls of 500)", model.FutureVoterStickerRolls) & _
  115. EmailRow("Special requests", model.SpecialRequests))
  116. End If
  117. html = html & "<p style=""color:#6d6574; font-size:12px; margin-top:24px;"">Questions about this order? Just reply to this email.</p>" & _
  118. "</td></tr>" & _
  119. "<tr><td style=""background:#f0e7f8; padding:16px 32px; text-align:center;"">" & _
  120. "<span style=""color:#6529a0; font-size:11px;"">Purple Envelope &middot; Addressing &amp; Barcoding</span>" & _
  121. "</td></tr>" & _
  122. "</table></td></tr></table></body></html>"
  123. BuildOrderDetailsEmailBody = html
  124. End Function
  125. Private Function EmailSection(sectionTitle, rowsHtml)
  126. If Len(rowsHtml) = 0 Then
  127. EmailSection = ""
  128. Else
  129. 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;"">" & _
  130. H(sectionTitle) & "</h2>" & _
  131. "<table role=""presentation"" width=""100%"" cellpadding=""0"" cellspacing=""0"">" & rowsHtml & "</table>"
  132. End If
  133. End Function
  134. Private Function EmailRow(label, value)
  135. If Len(Trim(value & "")) = 0 Then
  136. EmailRow = ""
  137. Else
  138. EmailRow = "<tr>" & _
  139. "<td style=""padding:6px 0; color:#6d6574; font-size:13px; width:45%; vertical-align:top;"">" & H(label) & "</td>" & _
  140. "<td style=""padding:6px 0; color:#201a27; font-size:13px; font-weight:600;"">" & H(value) & "</td>" & _
  141. "</tr>"
  142. End If
  143. End Function
  144. ' Null-safe boolean check for gating whole sections - a section's top-level "do you want
  145. ' this?" question isn't marked required client-side, so it may be missing (Null) rather
  146. ' than explicitly false.
  147. Private Function IsTrue(v)
  148. If IsNull(v) Then
  149. IsTrue = False
  150. Else
  151. IsTrue = CBool(v)
  152. End If
  153. End Function
  154. Private Function EmailYesNo(v)
  155. If IsNull(v) Then
  156. EmailYesNo = ""
  157. ElseIf CBool(v) Then
  158. EmailYesNo = "Yes"
  159. Else
  160. EmailYesNo = "No"
  161. End If
  162. End Function
  163. Private Function EmailDate(v)
  164. If IsNull(v) Then
  165. EmailDate = ""
  166. Else
  167. On Error Resume Next
  168. EmailDate = MonthName(Month(v)) & " " & Day(v) & ", " & Year(v)
  169. If Err.Number <> 0 Then EmailDate = ""
  170. Err.Clear
  171. On Error GoTo 0
  172. End If
  173. End Function
  174. Private Function NumOrZero(v)
  175. If IsNull(v) Or Not IsNumeric(v) Then
  176. NumOrZero = 0
  177. Else
  178. NumOrZero = CDbl(v)
  179. End If
  180. End Function
  181. End Class
  182. Dim OrderMailer_Class__Singleton
  183. Function OrderMailer()
  184. If IsEmpty(OrderMailer_Class__Singleton) Then
  185. Set OrderMailer_Class__Singleton = New OrderMailer_Class
  186. End If
  187. Set OrderMailer = OrderMailer_Class__Singleton
  188. End Function
  189. %>

Powered by TurnKey Linux.