From c10cb370bb943fa6bb6a947e0a515674f1ee1958 Mon Sep 17 00:00:00 2001 From: "Karel D. Kopecký" Date: Sun, 29 Jan 2023 23:16:31 +0100 Subject: config: add option for SMTP HELO/EHLO local domain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose go-smtp functionality for setting the domain name as a config option. This allows aerc to communicate with SMTP servers with strict antispam measures without relying on sendmail. In theory, this should be set to a fully qualified domain name, but some servers simply forbid the use of "localhost", so it is reasonable to let the user set whatever value works for them. For comparison, this is equivalent to the functionality of the "domain" option of msmtp. Signed-off-by: Karel D. Kopecký Acked-by: Robin Jarry --- commands/compose/send.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'commands') diff --git a/commands/compose/send.go b/commands/compose/send.go index 4029552e..1b65ab01 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -93,6 +93,10 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { if starttls_, ok := config.Params["smtp-starttls"]; ok { starttls = starttls_ == "yes" } + var domain string + if domain_, ok := config.Params["smtp-domain"]; ok { + domain = domain_ + } ctx := sendCtx{ uri: uri, scheme: scheme, @@ -100,6 +104,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { starttls: starttls, from: config.From, rcpts: rcpts, + domain: domain, } warn, err := composer.ShouldWarnAttachment() @@ -236,6 +241,7 @@ type sendCtx struct { starttls bool from *mail.Address rcpts []*mail.Address + domain string } func newSendmailSender(ctx sendCtx) (io.WriteCloser, error) { @@ -393,7 +399,7 @@ func newSmtpSender(ctx sendCtx) (io.WriteCloser, error) { ) switch ctx.scheme { case "smtp": - conn, err = connectSmtp(ctx.starttls, ctx.uri.Host) + conn, err = connectSmtp(ctx.starttls, ctx.uri.Host, ctx.domain) case "smtps": conn, err = connectSmtps(ctx.uri.Host) default: @@ -437,7 +443,7 @@ func newSmtpSender(ctx sendCtx) (io.WriteCloser, error) { return s.w, nil } -func connectSmtp(starttls bool, host string) (*smtp.Client, error) { +func connectSmtp(starttls bool, host string, domain string) (*smtp.Client, error) { serverName := host if !strings.ContainsRune(host, ':') { host += ":587" // Default to submission port @@ -448,6 +454,12 @@ func connectSmtp(starttls bool, host string) (*smtp.Client, error) { if err != nil { return nil, errors.Wrap(err, "smtp.Dial") } + if domain != "" { + err := conn.Hello(domain) + if err != nil { + return nil, errors.Wrap(err, "Hello") + } + } if sup, _ := conn.Extension("STARTTLS"); sup { if !starttls { err := errors.New("STARTTLS is supported by this server, " + -- cgit