Add configurable SMTP server
This commit is contained in:
parent
be99675f7b
commit
9093104c28
|
@ -41,7 +41,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
scsusers.Init(db, "test", "Example Test", "nobody@nowhere.com")
|
||||
scsusers.Init(db, "test", "Example Test", "nobody@nowhere.com", "localhost:25")
|
||||
a:=scsusers.UsernameAvailable("testuser")
|
||||
fmt.Printf("Initial test of username available: %v\n", a)
|
||||
a=scsusers.Register("testuser", email, "127.0.0.1")
|
||||
|
|
10
main.go
10
main.go
|
@ -26,6 +26,7 @@ type config struct {
|
|||
SiteName string
|
||||
FromEmail string
|
||||
Templates templates
|
||||
SMTPServer string
|
||||
db *sqlx.DB
|
||||
TablePrefix string
|
||||
}
|
||||
|
@ -38,11 +39,12 @@ type UserData struct {
|
|||
|
||||
var c config
|
||||
|
||||
func Init(dbin *sqlx.DB, tp, sitename, fromaddr string) {
|
||||
func Init(dbin *sqlx.DB, tp, sitename, fromaddr, smtpserver string) {
|
||||
c.db = dbin
|
||||
c.TablePrefix = tp
|
||||
c.SiteName = sitename
|
||||
c.FromEmail = fromaddr
|
||||
c.SMTPServer=smtpserver
|
||||
|
||||
SetRegistrationTemplate("")
|
||||
SetAlertTemplate("")
|
||||
|
@ -236,7 +238,7 @@ func sendRegistrationEmail(recipient, username, password string) bool {
|
|||
return false
|
||||
}
|
||||
subject := fmt.Sprintf("Welcome to %s", c.SiteName)
|
||||
err = SendMail("localhost:25", c.FromEmail, subject, body.String(), recipient)
|
||||
err = SendMail(c.SMTPServer, c.FromEmail, subject, body.String(), recipient)
|
||||
if err != nil {
|
||||
log.Printf("scsusers.SendRegistrationEmail: Error sending mail to %s: %s\n", recipient, err.Error())
|
||||
return false
|
||||
|
@ -265,7 +267,7 @@ func sendAlertEmail(username, recipient, message string) bool {
|
|||
}
|
||||
|
||||
subject := fmt.Sprintf("New activity on %s", c.SiteName)
|
||||
err = SendMail("localhost:25", c.FromEmail, subject, body.String(), recipient)
|
||||
err = SendMail(c.SMTPServer, c.FromEmail, subject, body.String(), recipient)
|
||||
if err != nil {
|
||||
log.Printf("scsusers.sendAlertEmail: Error sending mail to %s: %s\n", recipient, err.Error())
|
||||
return false
|
||||
|
@ -292,7 +294,7 @@ func sendRecoveryEmail(recipient, username, code string) bool {
|
|||
return false
|
||||
}
|
||||
subject := fmt.Sprintf("Account recovery at %s", c.SiteName)
|
||||
err = SendMail("localhost:25", c.FromEmail, subject, body.String(), recipient)
|
||||
err = SendMail(c.SMTPServer, c.FromEmail, subject, body.String(), recipient)
|
||||
if err != nil {
|
||||
log.Printf("scsusers.sendRecoveryEmail: Error sending mail to %s: %s\n", recipient, err.Error())
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue