From 27df532617ec363f734544f3c6628195427cef9c Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 16 Mar 2017 05:06:58 +0000 Subject: [PATCH] Authenticated SMTP is now fully functional. Tweaked the newlines in the validation email. --- config.go | 1 + install/install.go | 1 + user.go | 2 +- utils.go | 20 ++++++++++---------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/config.go b/config.go index 97b9d4e8..25346213 100644 --- a/config.go +++ b/config.go @@ -26,6 +26,7 @@ var site_email = "" // Should be a setting var smtp_server = "" var smtp_username = "" var smtp_password = "" +var smtp_port = "25" //var noavatar = "https://api.adorable.io/avatars/{width}/{id}@{site_url}.png" var noavatar = "https://api.adorable.io/avatars/285/{id}@" + site_url + ".png" diff --git a/install/install.go b/install/install.go index ad7b2b4f..12da223f 100644 --- a/install/install.go +++ b/install/install.go @@ -164,6 +164,7 @@ var site_email = "" // Should be a setting var smtp_server = "" var smtp_username = "" var smtp_password = "" +var smtp_port = "25" //var noavatar = "https://api.adorable.io/avatars/{width}/{id}@{site_url}.png" var noavatar = "https://api.adorable.io/avatars/285/{id}@" + site_url + ".png" diff --git a/user.go b/user.go index e1cdb61b..f3155ab4 100644 --- a/user.go +++ b/user.go @@ -315,7 +315,7 @@ func SendValidationEmail(username string, email string, token string) bool { } subject := "Validate Your Email @ " + site_name - msg := "Dear " + username + ", following your registration on our forums, we ask you to validate your email, so that we can confirm that this email actually belongs to you.\nClick on the following link to do so. http" + schema + "://" + site_url + "/user/edit/token/" + token + "\nIf you haven't created an account here, then please feel free to ignore this email.\nWe're sorry for the inconvenience this may have caused." + msg := "Dear " + username + ", following your registration on our forums, we ask you to validate your email, so that we can confirm that this email actually belongs to you.\n\nClick on the following link to do so. http" + schema + "://" + site_url + "/user/edit/token/" + token + "\n\nIf you haven't created an account here, then please feel free to ignore this email.\nWe're sorry for the inconvenience this may have caused." return SendEmail(email, subject, msg) } diff --git a/utils.go b/utils.go index 13d65fa2..487b69e6 100644 --- a/utils.go +++ b/utils.go @@ -73,16 +73,7 @@ func SendEmail(email string, subject string, msg string) bool { } body := "Subject: " + subject + "\n\n" + msg + "\n" - con, err := smtp.Dial(smtp_server) - if err != nil { - return false - } - - err = con.Mail(site_email) - if err != nil { - return false - } - err = con.Rcpt(email) + con, err := smtp.Dial(smtp_server + ":" + smtp_port) if err != nil { return false } @@ -95,6 +86,15 @@ func SendEmail(email string, subject string, msg string) bool { } } + err = con.Mail(site_email) + if err != nil { + return false + } + err = con.Rcpt(email) + if err != nil { + return false + } + email_data, err := con.Data() if err != nil { return false