Files
3f5b3cdd98 feat: add configurable SMTP HELO hostname (#2146)
* feat: add configurable SMTP HELO hostname

Allow the SMTP HELO/EHLO hostname to be configured separately from
the SMTP server hostname.

This is useful when the SMTP server requires clients to identify
themselves with a fully qualified hostname different from the server
address.

* chore: remove vendored dependency changes

* Bump go-pkgz/notify to v1.4.0 and document SMTP_HELO_HOST

The HELOHost field lands in go-pkgz/notify v1.4.0, so the branch needs the
bump to compile; v1.3.0 in master has no such field. The example module is
tidied alongside, as any change to backend/go.mod requires.

Documents the parameter in the parameters table and, separately, in the email
setup page: what it does, that leaving it unset keeps the previous `localhost`
greeting, and the case it exists for, a relay refusing the greeting under
Postfix `reject_non_fqdn_helo_hostname`.

Also records the current limit: verification emails for email authentication
go through go-pkgz/auth's own sender, which has no equivalent setting, so the
greeting there is unchanged.

* Bump go-pkgz/auth to v2.2.0 and apply SMTP_HELO_HOST to verification email

The verification email sender had no way to set the greeting, so a relay that
refuses the HELO would accept notifications and still reject sign-in emails.
EmailParams gains HELOHost in go-pkgz/auth v2.2.0, so the same SMTP_HELO_HOST
now drives both paths.

The example module is tidied alongside, as any change to backend/go.mod
requires.

---------

Co-authored-by: oli <someone@somewhere.tld>
Co-authored-by: Dmitry Verkhoturov <paskal.07@gmail.com>
2026-08-19 02:52:39 -05:00

95 lines
2.0 KiB
Go

package email
import "time"
// Option func type
type Option func(s *Sender)
// SMTP sets SMTP client. Such a client greets the server itself, so HELOHost doesn't apply to it.
func SMTP(smtp SMTPClient) Option {
return func(s *Sender) {
s.smtpClient = smtp
}
}
// Log sets the logger for the email package
func Log(l Logger) Option {
return func(s *Sender) {
s.logger = l
}
}
// Port sets SMTP port
func Port(port int) Option {
return func(s *Sender) {
s.port = port
}
}
// ContentType sets content type of the email
func ContentType(contentType string) Option {
return func(s *Sender) {
s.contentType = contentType
}
}
// Charset sets content charset of the email
func Charset(charset string) Option {
return func(s *Sender) {
s.contentCharset = charset
}
}
// TLS enables TLS support
func TLS(enabled bool) Option {
return func(s *Sender) {
s.tls = enabled
}
}
// STARTTLS enables STARTTLS support
func STARTTLS(enabled bool) Option {
return func(s *Sender) {
s.starttls = enabled
}
}
// InsecureSkipVerify skips certificate verification
func InsecureSkipVerify(enabled bool) Option {
return func(s *Sender) {
s.insecureSkipVerify = enabled
}
}
// HELOHost sets the SMTP HELO/EHLO hostname for connections created by Sender.
// Unset, the greeting stays net/smtp's "localhost". The value is passed to the server as-is,
// so an address literal like "[192.0.2.10]" works, and it has no effect on a client
// supplied with SMTP, which greets on its own.
func HELOHost(host string) Option {
return func(s *Sender) {
s.heloHost = host
}
}
// Auth sets smtp username and password
func Auth(smtpUserName, smtpPasswd string) Option {
return func(s *Sender) {
s.smtpUserName = smtpUserName
s.smtpPassword = smtpPasswd
}
}
// LoginAuth sets LOGIN auth method
func LoginAuth() Option {
return func(s *Sender) {
s.authMethod = authMethodLogin
}
}
// TimeOut sets smtp timeout
func TimeOut(timeOut time.Duration) Option {
return func(s *Sender) {
s.timeOut = timeOut
}
}