add SMTP support

it will be used in future update to add email sending capabilities
This commit is contained in:
Nicola Murino
2021-09-26 20:25:37 +02:00
parent 0661876e99
commit da0ccc6426
11 changed files with 302 additions and 12 deletions

View File

@@ -20,6 +20,7 @@ import (
"github.com/drakkan/sftpgo/v2/kms"
"github.com/drakkan/sftpgo/v2/mfa"
"github.com/drakkan/sftpgo/v2/sftpd"
"github.com/drakkan/sftpgo/v2/smtp"
"github.com/drakkan/sftpgo/v2/util"
)
@@ -42,6 +43,7 @@ func TestLoadConfigTest(t *testing.T) {
assert.NotEqual(t, dataprovider.Config{}, config.GetProviderConf())
assert.NotEqual(t, sftpd.Configuration{}, config.GetSFTPDConfig())
assert.NotEqual(t, httpclient.Config{}, config.GetHTTPConfig())
assert.NotEqual(t, smtp.Config{}, config.GetSMTPConfig())
confName := tempConfigName + ".json"
configFilePath := filepath.Join(configDir, confName)
err = config.LoadConfig(configDir, confName)
@@ -340,6 +342,24 @@ func TestSSHCommandsFromEnv(t *testing.T) {
}
}
func TestSMTPFromEnv(t *testing.T) {
reset()
os.Setenv("SFTPGO_SMTP__HOST", "smtp.example.com")
os.Setenv("SFTPGO_SMTP__PORT", "587")
t.Cleanup(func() {
os.Unsetenv("SFTPGO_SMTP__HOST")
os.Unsetenv("SFTPGO_SMTP__PORT")
})
configDir := ".."
err := config.LoadConfig(configDir, "")
assert.NoError(t, err)
smtpConfig := config.GetSMTPConfig()
assert.Equal(t, "smtp.example.com", smtpConfig.Host)
assert.Equal(t, 587, smtpConfig.Port)
}
func TestMFAFromEnv(t *testing.T) {
reset()