Add SSL support for sending email
This commit is contained in:
parent
d372d9f980
commit
474fa63985
2 changed files with 12 additions and 2 deletions
|
|
@ -44,10 +44,18 @@ proc sendMail(
|
|||
warn("Cannot send mail: no smtp from address configured (smtpFromAddr).")
|
||||
return
|
||||
|
||||
var client = newAsyncSmtp()
|
||||
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
|
||||
var client: AsyncSmtp
|
||||
if mailer.config.smtpTls:
|
||||
client = newAsyncSmtp(useSsl=false)
|
||||
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
|
||||
await client.startTls()
|
||||
elif mailer.config.smtpSsl:
|
||||
client = newAsyncSmtp(useSsl=true)
|
||||
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
|
||||
else:
|
||||
client = newAsyncSmtp(useSsl=false)
|
||||
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
|
||||
|
||||
if mailer.config.smtpUser.len > 0:
|
||||
await client.auth(mailer.config.smtpUser, mailer.config.smtpPassword)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type
|
|||
smtpPassword*: string
|
||||
smtpFromAddr*: string
|
||||
smtpTls*: bool
|
||||
smtpSsl*: bool
|
||||
mlistAddress*: string
|
||||
recaptchaSecretKey*: string
|
||||
recaptchaSiteKey*: string
|
||||
|
|
@ -57,6 +58,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
|||
result.smtpPassword = root{"smtpPassword"}.getStr("")
|
||||
result.smtpFromAddr = root{"smtpFromAddr"}.getStr("")
|
||||
result.smtpTls = root{"smtpTls"}.getBool(false)
|
||||
result.smtpSsl = root{"smtpSsl"}.getBool(false)
|
||||
result.mlistAddress = root{"mlistAddress"}.getStr("")
|
||||
result.recaptchaSecretKey = root{"recaptchaSecretKey"}.getStr("")
|
||||
result.recaptchaSiteKey = root{"recaptchaSiteKey"}.getStr("")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue