Skip to content

Commit

Permalink
Add more mail config options
Browse files Browse the repository at this point in the history
  • Loading branch information
sblaisot committed Nov 8, 2023
1 parent 23138d1 commit 0539230
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 26 deletions.
9 changes: 8 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ example), you can use the --appdir flag like this:

if flagMailhog {
cfg := config.GetConfig()
cfg.Mail.NativeTLS = false
cfg.Mail.DisableTLS = true
cfg.Mail.Port = 1025
}
Expand Down Expand Up @@ -220,9 +221,15 @@ func init() {
flags.String("mail-password", "", "mail smtp password")
checkNoErr(viper.BindPFlag("mail.password", flags.Lookup("mail-password")))

flags.Bool("mail-disable-tls", false, "disable smtp over tls")
flags.Bool("mail-use-ssl", false, "use ssl for mail sending (smtps)")
checkNoErr(viper.BindPFlag("mail.use_ssl", flags.Lookup("mail-use-ssl")))

flags.Bool("mail-disable-tls", false, "disable starttls on smtp")
checkNoErr(viper.BindPFlag("mail.disable_tls", flags.Lookup("mail-disable-tls")))

flags.String("mail-local-name", "localhost", "hostname sent to the smtp server with the HELO command")
checkNoErr(viper.BindPFlag("mail.local_name", flags.Lookup("mail-local-name")))

flags.String("move-url", "https://move.cozycloud.cc/", "URL for the move wizard")
checkNoErr(viper.BindPFlag("move.url", flags.Lookup("move-url")))

Expand Down
29 changes: 20 additions & 9 deletions cozy.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,34 @@ mail:
# mail smtp host - flags: --mail-host
host: smtp.home
# mail smtp port - flags: --mail-port
port: 465
port: 587
# mail smtp username - flags: --mail-username
username: {{.Env.COZY_MAIL_USERNAME}}
username: {{ .Env.COZY_MAIL_USERNAME }}
# mail smtp password - flags: --mail-password
password: {{.Env.COZY_MAIL_PASSWORD}}
# disable mail tls - flags: --mail-disable-tls
password: {{ .Env.COZY_MAIL_PASSWORD }}
# Use SSL connection (SMTPS)
# Means no STARTTLS
# flags: --mail-use-ssl
use_ssl: false
# disable mail STARTTLS
# Means using plain unencrypted SMTP
# flags: --mail-disable-tls
disable_tls: false
# skip the certificate validation (may be useful on localhost)
skip_certificate_validation: false
# Local Name
# The hostname sent to the SMTP server with the HELO command
# Defaults to localhost
# flags: --mail-local-name
local_name: cozy.domain.example
# It is also possible to override the mail server per context.
contexts:
beta:
# If the host is set to "-", no mail will be sent on this context
host: smtp.cozy.beta
port: 465
username: {{.Env.COZY_BETA_MAIL_USERNAME}}
password: {{.Env.COZY_BETA_MAIL_PASSWORD}}
port: 587
username: {{ .Env.COZY_BETA_MAIL_USERNAME }}
password: {{ .Env.COZY_BETA_MAIL_PASSWORD }}

# location of the database for IP -> City lookups - flags: --geodb
# See https://dev.maxmind.com/geoip/geoip2/geolite2/
Expand Down Expand Up @@ -303,7 +314,7 @@ deprecated_apps:
apps:
# - software_id: "github.com/cozy/some-app"
# name: "some-app"
# store_urls:
# store_urls:
# iphone: https://some-apple-store-url
# android: https://some-android-store-url

Expand Down Expand Up @@ -331,7 +342,7 @@ notifications:
beta:
provider: api_sen
url: https://sms.cozy.beta/api/send
token: {{.Env.COZY_BETA_SMS_TOKEN}}
token: {{ .Env.COZY_BETA_SMS_TOKEN }}

flagship:
contexts:
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,10 @@ func UseViper(v *viper.Viper) error {
Port: v.GetInt("mail.port"),
Username: v.GetString("mail.username"),
Password: v.GetString("mail.password"),
NativeTLS: v.GetBool("mail.use_ssl"),
DisableTLS: v.GetBool("mail.disable_tls"),
SkipCertificateValidation: v.GetBool("mail.skip_certificate_validation"),
LocalName: v.GetString("mail.local_name"),
},
MailPerContext: v.GetStringMap("mail.contexts"),
Contexts: v.GetStringMap("contexts"),
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ func TestConfigUnmarshal(t *testing.T) {
Port: 25,
Username: "some-username",
Password: "some-password",
NativeTLS: false,
DisableTLS: true,
SkipCertificateValidation: true,
LocalName: "some.host",

Check failure on line 98 in pkg/config/config/config_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
}, cfg.Mail)
assert.EqualValues(t, map[string]interface{}{
"my-context": map[string]interface{}{"host": "-"},
Expand Down
36 changes: 20 additions & 16 deletions pkg/config/config/testdata/full_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ assets_polling_disabled: true
assets_polling_interval: 1h

fs:
url: https://some-url
url:
https://some-url
# root_ca: /some/ca.crt
EndpointType: internal
can_query_info: true
default_layout: 2
default_layout: 2
versioning:
max_number_of_versions_to_keep: 4
min_delay_between_two_versions: 1m

couchdb:
url: https://some-couchdb-url
url:
https://some-couchdb-url
#root_ca: /some/ca/path.crt

redis:
Expand Down Expand Up @@ -61,13 +63,15 @@ mail:
reply_to: support@cozycloud.cc
contexts:
my-context:
host: '-'
host: "-"
host: localhost
username: some-username
password: some-password
port: 25
use_ssl: false
disable_tls: true
skip_certificate_validation: true
local_name: some.host

geodb: /geo/db/path

Expand All @@ -80,13 +84,13 @@ konnectors:
registries:
default: []
example:
- https://registry-url-1
- https://registry-url-2
- https://registry-url-1
- https://registry-url-2

office:
foo:
onlyoffice_url: https://onlyoffice-url
onlyoffice_inbox_secret: inbox_secret
onlyoffice_inbox_secret: inbox_secret
onlyoffice_outbox_secret: outbox_secret

clouderies:
Expand Down Expand Up @@ -156,15 +160,15 @@ contexts:
help_link: https://cozy.io/fr/support
enable_premium_links: false
claudy_actions:
- desktop
- support
- desktop
- support
additional_platform_apps:
- some-app
- some-app
features:
- hide_konnector_errors: true
- home.konnectors.hide-errors: true
- home_hidden_apps:
- foobar
- hide_konnector_errors: true
- home.konnectors.hide-errors: true
- home_hidden_apps:
- foobar
home_logos:
/logos/1.png: 'Title 1'
/logos/2.png: 'Title 2'
/logos/1.png: "Title 1"
/logos/2.png: "Title 2"
4 changes: 4 additions & 0 deletions worker/mails/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ func SendMail(ctx *job.WorkerContext) error {
port, _ := ctxConfig["port"].(int)
username, _ := ctxConfig["username"].(string)
password, _ := ctxConfig["username"].(string)
UseSSL, _ := ctxConfig["use_ssl"].(bool)
disableTLS, _ := ctxConfig["disable_tls"].(bool)
skipCertValid, _ := ctxConfig["skip_certificate_validation"].(bool)
LocalName, _ := ctxConfig["local_name"].(string)
opts.Dialer = &gomail.DialerOptions{
Host: host,
Port: port,
Username: username,
Password: password,
NativeTLS: UseSSL,

Check failure on line 72 in worker/mails/mail.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
DisableTLS: disableTLS,
SkipCertificateValidation: skipCertValid,
LocalName: LocalName,
}
}
}
Expand Down

0 comments on commit 0539230

Please sign in to comment.