[#3097] added SmtpConfig.LocalName option

This commit is contained in:
Gani Georgiev
2023-08-17 19:07:56 +03:00
parent 53b20ec104
commit b2ac538580
38 changed files with 3461 additions and 3363 deletions
+7
View File
@@ -371,6 +371,12 @@ type SmtpConfig struct {
// When set to false StartTLS command is send, leaving the server
// to decide whether to upgrade the connection or not.
Tls bool `form:"tls" json:"tls"`
// LocalName is optional domain name or IP address used for the
// EHLO/HELO exchange (if not explicitly set, defaults to "localhost").
//
// This is required only by some SMTP servers, such as Gmail SMTP-relay.
LocalName string `form:"localName" json:"localName"`
}
// Validate makes SmtpConfig validatable by implementing [validation.Validatable] interface.
@@ -393,6 +399,7 @@ func (c SmtpConfig) Validate() error {
// validation.When(c.Enabled, validation.Required),
validation.In(mailer.SmtpAuthLogin, mailer.SmtpAuthPlain),
),
validation.Field(&c.LocalName, is.Host),
)
}
+20
View File
@@ -477,6 +477,26 @@ func TestSmtpConfigValidate(t *testing.T) {
},
false,
},
// invalid ehlo/helo name
{
settings.SmtpConfig{
Enabled: true,
Host: "example.com",
Port: 100,
LocalName: "invalid!",
},
true,
},
// valid ehlo/helo name
{
settings.SmtpConfig{
Enabled: true,
Host: "example.com",
Port: 100,
LocalName: "example.com",
},
false,
},
}
for i, scenario := range scenarios {