Merge pull request #244 from Yardanico/emailtls

Add ability to enable TLS for SMTP
This commit is contained in:
Joey 2020-05-10 06:58:18 -06:00 • committed by GitHub
commit f0bfd5516a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -46,6 +46,8 @@ proc sendMail(
var client = newAsyncSmtp() var client = newAsyncSmtp()
await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort)) await client.connect(mailer.config.smtpAddress, Port(mailer.config.smtpPort))
if mailer.config.smtpTls:
await client.startTls()
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)

View file

@ -234,7 +234,7 @@ proc initialiseDb(admin: tuple[username, password, email: string],
proc initialiseConfig( proc initialiseConfig(
name, title, hostname: string, name, title, hostname: string,
recaptcha: tuple[siteKey, secretKey: string], recaptcha: tuple[siteKey, secretKey: string],
smtp: tuple[address, user, password, fromAddr: string], smtp: tuple[address, user, password, fromAddr: string, tls: bool],
isDev: bool, isDev: bool,
dbPath: string, dbPath: string,
ga: string="" ga: string=""
@ -251,6 +251,7 @@ proc initialiseConfig(
"smtpUser": %smtp.user, "smtpUser": %smtp.user,
"smtpPassword": %smtp.password, "smtpPassword": %smtp.password,
"smtpFromAddr": %smtp.fromAddr, "smtpFromAddr": %smtp.fromAddr,
"smtpTls": %smtp.tls,
"isDev": %isDev, "isDev": %isDev,
"dbPath": %dbPath "dbPath": %dbPath
} }
@ -294,6 +295,7 @@ These can be changed later in the generated forum.json file.
let smtpUser = question("SMTP user: ") let smtpUser = question("SMTP user: ")
let smtpPassword = readPasswordFromStdin("SMTP pass: ") let smtpPassword = readPasswordFromStdin("SMTP pass: ")
let smtpFromAddr = question("SMTP sending email address (eg: mail@mail.hostname.com): ") let smtpFromAddr = question("SMTP sending email address (eg: mail@mail.hostname.com): ")
let smtpTls = parseBool(question("Enable TLS for SMTP: "))
echo("The following is optional. You can specify your Google Analytics ID " & echo("The following is optional. You can specify your Google Analytics ID " &
"if you wish. Otherwise just leave it blank.") "if you wish. Otherwise just leave it blank.")
@ -303,7 +305,7 @@ These can be changed later in the generated forum.json file.
let dbPath = "nimforum.db" let dbPath = "nimforum.db"
initialiseConfig( initialiseConfig(
name, title, hostname, (recaptchaSiteKey, recaptchaSecretKey), name, title, hostname, (recaptchaSiteKey, recaptchaSecretKey),
(smtpAddress, smtpUser, smtpPassword, smtpFromAddr), isDev=false, (smtpAddress, smtpUser, smtpPassword, smtpFromAddr, smtpTls), isDev=false,
dbPath, ga dbPath, ga
) )
@ -338,7 +340,7 @@ when isMainModule:
"Development Forum", "Development Forum",
"localhost", "localhost",
recaptcha=("", ""), recaptcha=("", ""),
smtp=("", "", "", ""), smtp=("", "", "", "", false),
isDev=true, isDev=true,
dbPath dbPath
) )
@ -355,7 +357,7 @@ when isMainModule:
"Test Forum", "Test Forum",
"localhost", "localhost",
recaptcha=("", ""), recaptcha=("", ""),
smtp=("", "", "", ""), smtp=("", "", "", "", false),
isDev=true, isDev=true,
dbPath dbPath
) )

View file

@ -17,6 +17,7 @@ type
smtpUser*: string smtpUser*: string
smtpPassword*: string smtpPassword*: string
smtpFromAddr*: string smtpFromAddr*: string
smtpTls*: bool
mlistAddress*: string mlistAddress*: string
recaptchaSecretKey*: string recaptchaSecretKey*: string
recaptchaSiteKey*: string recaptchaSiteKey*: string
@ -55,6 +56,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
result.smtpUser = root{"smtpUser"}.getStr("") result.smtpUser = root{"smtpUser"}.getStr("")
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.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("")