Separate email address and username for smtp

A username can now be set for SMTP. If not set, the send from address
will be used as before.
This commit is contained in:
Harvey Tindall 2020-10-11 22:32:51 +01:00
parent 5fd2e81fe4
commit 8672d7dc18
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 27 additions and 4 deletions

View File

@ -37,7 +37,7 @@ I chose to rewrite the python [jellyfin-accounts](https://github.com/hrfee/jelly
Available on the AUR as [jfa-go](https://aur.archlinux.org/packages/jfa-go/) or [jfa-go-git](https://aur.archlinux.org/packages/jfa-go-git/).
For other platforms, grab an archive from the release section for your platform, and extract `jfa-go` and `data` to the same directory.
For other platforms, grab an archive from the release section for your platform (or nightly builds [here](https://builds.hrfee.pw/view/hrfee/jfa-go)), and extract `jfa-go` and `data` to the same directory.
* For linux users, you can place them inside `/opt/jfa-go` and then run
`sudo ln -s /opt/jfa-go/jfa-go /usr/bin/jfa-go` to place it in your PATH.

View File

@ -455,6 +455,14 @@
"name": "SMTP (Email)",
"description": "SMTP Server connection settings."
},
"username": {
"name": "Username",
"required": false,
"requires_restart": false,
"type": "text",
"value": "",
"description": "Username for SMTP. Leave blank to user send from address as username."
},
"encryption": {
"name": "Encryption Method",
"required": false,

View File

@ -530,6 +530,7 @@
},
"smtp": {
"order": [
"username",
"encryption",
"server",
"port",
@ -539,6 +540,14 @@
"name": "SMTP (Email)",
"description": "SMTP Server connection settings."
},
"username": {
"name": "Username",
"required": false,
"requires_restart": false,
"type": "text",
"value": "",
"description": "Username for SMTP. Leave blank to user send from address as username."
},
"encryption": {
"name": "Encryption Method",
"required": false,

View File

@ -113,7 +113,13 @@ func NewEmailer(app *appContext) *Emailer {
if app.config.Section("smtp").Key("encryption").String() == "ssl_tls" {
sslTls = true
}
emailer.NewSMTP(app.config.Section("smtp").Key("server").String(), app.config.Section("smtp").Key("port").MustInt(465), app.config.Section("smtp").Key("password").String(), app.host, sslTls)
username := ""
if u := app.config.Section("smtp").Key("username").MustString(""); u != "" {
username = u
} else {
username = emailer.fromAddr
}
emailer.NewSMTP(app.config.Section("smtp").Key("server").String(), app.config.Section("smtp").Key("port").MustInt(465), username, app.config.Section("smtp").Key("password").String(), app.host, sslTls)
} else if method == "mailgun" {
emailer.NewMailgun(app.config.Section("mailgun").Key("api_url").String(), app.config.Section("mailgun").Key("api_key").String())
}
@ -135,9 +141,9 @@ func (emailer *Emailer) NewMailgun(url, key string) {
}
// NewSMTP returns an SMTP emailClient.
func (emailer *Emailer) NewSMTP(server string, port int, password, host string, sslTLS bool) {
func (emailer *Emailer) NewSMTP(server string, port int, username, password, host string, sslTLS bool) {
emailer.sender = &SMTP{
auth: smtp.PlainAuth("", emailer.fromAddr, password, host),
auth: smtp.PlainAuth("", username, password, host),
server: server,
host: host,
port: port,