Implement config for SMTP

This commit is contained in:
Rene Vergara 2023-01-24 14:01:08 -06:00
parent e927cb26f3
commit 597ac5efc3
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
8 changed files with 92 additions and 13 deletions

View file

@ -3,10 +3,13 @@
module Main where
import Config
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.IO as TIO
import Data.Time.Clock
import Database.MongoDB
import qualified Network.Mail.Mime as M
import Network.Mail.SMTP
import qualified Network.Socket as NS
import Owner
import System.Exit
@ -29,7 +32,7 @@ main = do
putStr "Expiring users: "
print $ length users
mapM_ (emailOwner loadedConfig) users
else die "MongoDB connection failed!"
else die "MongoDB connection failed! :("
where
emailOwner :: Config -> Document -> IO ()
emailOwner config doc = do
@ -37,17 +40,29 @@ main = do
case o of
Nothing -> putStrLn "Couldn't parse owner record."
Just o1 -> do
msgtmp <- TIO.readFile "email.html"
txttmp <- TIO.readFile "email.txt"
let msg =
L.replace
"PLACEHOLDER_EXPIRATION"
(L.pack $ show (oexpiration o1)) $
L.replace "PLACEHOLDER_NAME" (L.fromStrict $ ofirst o1) msgtmp
let txt =
L.replace
"PLACEHOLDER_EXPIRATION"
(L.pack $ show (oexpiration o1)) $
L.replace "PLACEHOLDER_NAME" (L.fromStrict $ ofirst o1) txttmp
mail <-
M.simpleMail
(Address (Just $ oname o1) (oemail o1))
(Address (Just "ZGo Support") "contact@zgo.cash")
"ZGo session about to expire"
"Your ZGo session is about to expire"
"<p>Your ZGo session is about to expire</p>"
txt
msg
[]
sendMailWithLogin'
"127.0.0.1"
1025
"contact@zgo.cash"
"uib3K8BkCPexl_wr5bYfrg"
(c_smtpHost config)
(fromInteger (c_smtpPort config) :: NS.PortNumber)
(c_smtpUser config)
(c_smtpPwd config)
mail

49
email.html Normal file
View file

@ -0,0 +1,49 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ZGo Session about to Expire</title>
<link rel="preload" href="https://zgo.cash/fonts/Spartan-Regular.woff2" as="font" type="font/woff2" crossorigin>
<link rel="icon" type="image/x-icon" href="https://zgo.cash/images/favicon.ico" />
<link rel="stylesheet" href="https://zgo.cash/css/default.css" />
<link rel="stylesheet" href="https://zgo.cash/css/fontawesome.css" />
<link rel="stylesheet" href="https://zgo.cash/css/all.css" />
</head>
<body>
<header>
<a href="https://zgo.cash/"><img src="https://zgo.cash/images/logo-new-transparent.png" height="100" style="margin:5px; vertical-align: middle;" /></a>
</header>
<main role="main">
<p>Hello PLACEHOLDER_NAME,</p>
<p>Your current ZGo session will expire on PLACEHOLDER_EXPIRATION. To avoid any service disruption, please proceed to activate a new session in the app.</p>
<p>If your session does expire, your shop and all its data will be readily available for you when you activate your next session.</p>
<br>
<p>Thank you for offering your customers the option to pay with Zcash with us,<br>The ZGo team</p>
</main>
<footer>
<table width="100%" cellspacing="0">
<tr>
<td align="left">
<p>
<a href="https://zeal.center/@zgo" target="_blank" rel="me"><i class="fa-brands fa-mastodon fa-2xl" style="color: #ff5722;"></i></a>
<a href="mailto:contact@zgo.cash" target="_blank"><i class="fa-solid fa-envelope fa-2xl" style="color: #ff5722;"></i></a>
<a href="https://matrix.to/#/#zgo-support:vergara.tech" target="_blank"><i class="fa-solid fa-comments fa-2xl" style="color: #ff5722;"></i></a>
</p>
</td>
<td align="right">
<i class="fa-regular fa-copyright"></i>2023 Copyright Vergara Technologies LLC<br>
ZGo is supported by a <a href="https://zcashgrants.org/" target="_blank">Zcash Community Grant</a><br>
</td>
</tr>
</table>
</footer>
</body>
</html>

9
email.txt Normal file
View file

@ -0,0 +1,9 @@
Hello PLACEHOLDER_NAME,
Your current ZGo session will expire on PLACEHOLDER_EXPIRATION. To avoid any
service disruption, please proceed to activate a new session in the app.
If you session does expire, your shop and all its data will be readily
available for you when you activate your next session.
Thank you for offering your customers the option to pay with Zcash with us,
The ZGo Team

View file

@ -41,6 +41,8 @@ executables:
- time
- mime-mail
- smtp-mail
- text
- network
tests:
zgo-notifier-test:

View file

@ -37,7 +37,7 @@ packages:
#
extra-deps:
- git: https://git.vergara.tech/Vergara_Tech/zgo-backend.git
commit: a8e1c1b4d8365c6c9f1959bf597558f50bb1a1cc
commit: f2c04ec8d5723b54d16f2657dcb7b8476bb0d1ec
- blake3-0.2@sha256:d1146b9a51ccfbb0532780778b6d016a614e3d44c05d8c1923dde9a8be869045,2448
- git: https://github.com/reach-sh/haskell-hexstring.git
commit: 085c16fb21b9f856a435a3faab980e7e0b319341

View file

@ -5,15 +5,15 @@
packages:
- completed:
commit: a8e1c1b4d8365c6c9f1959bf597558f50bb1a1cc
commit: f2c04ec8d5723b54d16f2657dcb7b8476bb0d1ec
git: https://git.vergara.tech/Vergara_Tech/zgo-backend.git
name: zgo-backend
pantry-tree:
sha256: 223b93209879687086a70437f8913eee611bf9f6876b0d6b124a70dbe741c447
sha256: 06d62c7a8f7862ac49f8d052d2b1c6328ce82a10be2d0644983321295751857b
size: 1319
version: 1.2.0
original:
commit: a8e1c1b4d8365c6c9f1959bf597558f50bb1a1cc
commit: f2c04ec8d5723b54d16f2657dcb7b8476bb0d1ec
git: https://git.vergara.tech/Vergara_Tech/zgo-backend.git
- completed:
hackage: blake3-0.2@sha256:d1146b9a51ccfbb0532780778b6d016a614e3d44c05d8c1923dde9a8be869045,2448

View file

@ -22,8 +22,6 @@ source-repository head
location: https://git.vergara.tech/Vergara_Tech/zgo-notifier
library
exposed-modules:
Lib
other-modules:
Paths_zgo_notifier
hs-source-dirs:
@ -44,7 +42,9 @@ executable zgo-notifier
, blake3
, mime-mail
, mongoDB
, network
, smtp-mail
, text
, time
, zgo-backend
, zgo-notifier

View file

@ -10,3 +10,7 @@ port = 3000
tls = false
certificate = "/path/to/cert.pem"
key = "/path/to/key.pem"
smtpHost = "127.0.0.1"
smtpPort = 1025
smtpUser = "contact@zgo.cash"
smtpPwd = "uib3K8BkCPexl_wr5bYfrg"