From 8672d7dc1845df409879375e6b5d8aa3b5689ce0 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 11 Oct 2020 22:32:51 +0100 Subject: [PATCH] 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. --- README.md | 2 +- config/config-base.json | 8 ++++++++ data/config-base.json | 9 +++++++++ email.go | 12 +++++++++--- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0cc98d3..b00a45a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config/config-base.json b/config/config-base.json index aaaac34..61240d3 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -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, diff --git a/data/config-base.json b/data/config-base.json index b0a8953..654fb56 100644 --- a/data/config-base.json +++ b/data/config-base.json @@ -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, diff --git a/email.go b/email.go index e26fb82..faa7ffe 100644 --- a/email.go +++ b/email.go @@ -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,