mirror of
https://github.com/hrfee/jfa-go.git
synced 2026-03-18 21:50:33 +01:00
email: Allow no SMTP encryption
added a "none" option.
This commit is contained in:
@@ -791,6 +791,7 @@ sections:
|
|||||||
options:
|
options:
|
||||||
- ["ssl_tls", "SSL/TLS"]
|
- ["ssl_tls", "SSL/TLS"]
|
||||||
- ["starttls", "STARTTLS"]
|
- ["starttls", "STARTTLS"]
|
||||||
|
- ["none", "None (only use locally!)"]
|
||||||
value: starttls
|
value: starttls
|
||||||
description: Your email provider should provide different ports for each encryption
|
description: Your email provider should provide different ports for each encryption
|
||||||
method. Generally 465 for ssl_tls, 587 for starttls.
|
method. Generally 465 for ssl_tls, 587 for starttls.
|
||||||
|
|||||||
16
email.go
16
email.go
@@ -81,9 +81,14 @@ func NewEmailer(app *appContext) *Emailer {
|
|||||||
}
|
}
|
||||||
method := app.config.Section("email").Key("method").String()
|
method := app.config.Section("email").Key("method").String()
|
||||||
if method == "smtp" {
|
if method == "smtp" {
|
||||||
sslTLS := false
|
enc := sMail.EncryptionSTARTTLS
|
||||||
if app.config.Section("smtp").Key("encryption").String() == "ssl_tls" {
|
switch app.config.Section("smtp").Key("encryption").String() {
|
||||||
sslTLS = true
|
case "ssl_tls":
|
||||||
|
enc = sMail.EncryptionSSLTLS
|
||||||
|
case "starttls":
|
||||||
|
enc = sMail.EncryptionSTARTTLS
|
||||||
|
case "none":
|
||||||
|
enc = sMail.EncryptionNone
|
||||||
}
|
}
|
||||||
username := app.config.Section("smtp").Key("username").MustString("")
|
username := app.config.Section("smtp").Key("username").MustString("")
|
||||||
password := app.config.Section("smtp").Key("password").String()
|
password := app.config.Section("smtp").Key("password").String()
|
||||||
@@ -95,7 +100,7 @@ func NewEmailer(app *appContext) *Emailer {
|
|||||||
proxyConf = &app.proxyConfig
|
proxyConf = &app.proxyConfig
|
||||||
}
|
}
|
||||||
authType := sMail.AuthType(app.config.Section("smtp").Key("auth_type").MustInt(4))
|
authType := sMail.AuthType(app.config.Section("smtp").Key("auth_type").MustInt(4))
|
||||||
err := emailer.NewSMTP(app.config.Section("smtp").Key("server").String(), app.config.Section("smtp").Key("port").MustInt(465), username, password, sslTLS, app.config.Section("smtp").Key("ssl_cert").MustString(""), app.config.Section("smtp").Key("hello_hostname").String(), app.config.Section("smtp").Key("cert_validation").MustBool(true), authType, proxyConf)
|
err := emailer.NewSMTP(app.config.Section("smtp").Key("server").String(), app.config.Section("smtp").Key("port").MustInt(465), username, password, enc, app.config.Section("smtp").Key("ssl_cert").MustString(""), app.config.Section("smtp").Key("hello_hostname").String(), app.config.Section("smtp").Key("cert_validation").MustBool(true), authType, proxyConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.err.Printf(lm.FailedInitSMTP, err)
|
app.err.Printf(lm.FailedInitSMTP, err)
|
||||||
}
|
}
|
||||||
@@ -121,9 +126,10 @@ type SMTP struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSMTP returns an SMTP emailClient.
|
// NewSMTP returns an SMTP emailClient.
|
||||||
func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string, helloHostname string, validateCertificate bool, authType sMail.AuthType, proxy *easyproxy.ProxyConfig) (err error) {
|
func (emailer *Emailer) NewSMTP(server string, port int, username, password string, encryption sMail.Encryption, certPath string, helloHostname string, validateCertificate bool, authType sMail.AuthType, proxy *easyproxy.ProxyConfig) (err error) {
|
||||||
sender := &SMTP{}
|
sender := &SMTP{}
|
||||||
sender.Client = sMail.NewSMTPClient()
|
sender.Client = sMail.NewSMTPClient()
|
||||||
|
sender.Client.Encryption = encryption
|
||||||
if sslTLS {
|
if sslTLS {
|
||||||
sender.Client.Encryption = sMail.EncryptionSSLTLS
|
sender.Client.Encryption = sMail.EncryptionSSLTLS
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user