Merge pull request #248 from hvnsweeting/ssl-support
Add SSL support for sending email
This commit is contained in:
commit
d808749054
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).")
|
warn("Cannot send mail: no smtp from address configured (smtpFromAddr).")
|
||||||
return
|
return
|
||||||
|
|
||||||
var client = newAsyncSmtp()
|
var client: AsyncSmtp
|
||||||
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
|
|
||||||
if mailer.config.smtpTls:
|
if mailer.config.smtpTls:
|
||||||
|
client = newAsyncSmtp(useSsl=false)
|
||||||
|
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
|
||||||
await client.startTls()
|
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:
|
if mailer.config.smtpUser.len > 0:
|
||||||
await client.auth(mailer.config.smtpUser, mailer.config.smtpPassword)
|
await client.auth(mailer.config.smtpUser, mailer.config.smtpPassword)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ type
|
||||||
smtpPassword*: string
|
smtpPassword*: string
|
||||||
smtpFromAddr*: string
|
smtpFromAddr*: string
|
||||||
smtpTls*: bool
|
smtpTls*: bool
|
||||||
|
smtpSsl*: bool
|
||||||
mlistAddress*: string
|
mlistAddress*: string
|
||||||
recaptchaSecretKey*: string
|
recaptchaSecretKey*: string
|
||||||
recaptchaSiteKey*: string
|
recaptchaSiteKey*: string
|
||||||
|
|
@ -57,6 +58,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
||||||
result.smtpPassword = root{"smtpPassword"}.getStr("")
|
result.smtpPassword = root{"smtpPassword"}.getStr("")
|
||||||
result.smtpFromAddr = root{"smtpFromAddr"}.getStr("")
|
result.smtpFromAddr = root{"smtpFromAddr"}.getStr("")
|
||||||
result.smtpTls = root{"smtpTls"}.getBool(false)
|
result.smtpTls = root{"smtpTls"}.getBool(false)
|
||||||
|
result.smtpSsl = root{"smtpSsl"}.getBool(false)
|
||||||
result.mlistAddress = root{"mlistAddress"}.getStr("")
|
result.mlistAddress = root{"mlistAddress"}.getStr("")
|
||||||
result.recaptchaSecretKey = root{"recaptchaSecretKey"}.getStr("")
|
result.recaptchaSecretKey = root{"recaptchaSecretKey"}.getStr("")
|
||||||
result.recaptchaSiteKey = root{"recaptchaSiteKey"}.getStr("")
|
result.recaptchaSiteKey = root{"recaptchaSiteKey"}.getStr("")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue