mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 08:53:48 +03:00
8096441f67
the default transport is still just "direct delivery", where we connect to the destination domain's MX servers. other transports are: - regular smtp without authentication, this is relaying to a smarthost. - submission with authentication, e.g. to a third party email sending service. - direct delivery, but with with connections going through a socks proxy. this can be helpful if your ip is blocked, you need to get email out, and you have another IP that isn't blocked. keep in mind that for all of the above, appropriate SPF/DKIM settings have to be configured. the "dnscheck" for a domain does a check for any SOCKS IP in the SPF record. SPF for smtp/submission (ranges? includes?) and any DKIM requirements cannot really be checked. which transport is used can be configured through routes. routes can be set on an account, a domain, or globally. the routes are evaluated in that order, with the first match selecting the transport. these routes are evaluated for each delivery attempt. common selection criteria are recipient domain and sender domain, but also which delivery attempt this is. you could configured mox to attempt sending through a 3rd party from the 4th attempt onwards. routes and transports are optional. if no route matches, or an empty/zero transport is selected, normal direct delivery is done. we could already "submit" emails with 3rd party accounts with "sendmail". but we now support more SASL authentication mechanisms with SMTP (not only PLAIN, but also SCRAM-SHA-256, SCRAM-SHA-1 and CRAM-MD5), which sendmail now also supports. sendmail will use the most secure mechanism supported by the server, or the explicitly configured mechanism. for issue #36 by dmikushin. also based on earlier discussion on hackernews.
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package smtpserver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/mjl-/mox/dsn"
|
|
"github.com/mjl-/mox/queue"
|
|
"github.com/mjl-/mox/smtp"
|
|
"github.com/mjl-/mox/store"
|
|
)
|
|
|
|
// compose dsn message and add it to the queue for delivery to rcptTo.
|
|
func queueDSN(ctx context.Context, c *conn, rcptTo smtp.Path, m dsn.Message) error {
|
|
buf, err := m.Compose(c.log, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var bufUTF8 []byte
|
|
if c.smtputf8 {
|
|
bufUTF8, err = m.Compose(c.log, true)
|
|
if err != nil {
|
|
c.log.Errorx("composing dsn with utf-8 for incoming delivery for unknown user, continuing with ascii-only dsn", err)
|
|
}
|
|
}
|
|
|
|
f, err := store.CreateMessageTemp("smtp-dsn")
|
|
if err != nil {
|
|
return fmt.Errorf("creating temp file: %w", err)
|
|
}
|
|
defer func() {
|
|
if f != nil {
|
|
err := os.Remove(f.Name())
|
|
c.log.Check(err, "removing temporary dsn message file")
|
|
err = f.Close()
|
|
c.log.Check(err, "closing temporary dsn message file")
|
|
}
|
|
}()
|
|
if _, err := f.Write([]byte(buf)); err != nil {
|
|
return fmt.Errorf("writing dsn file: %w", err)
|
|
}
|
|
|
|
// Queue DSN with null reverse path so failures to deliver will eventually drop the
|
|
// message instead of causing delivery loops.
|
|
// ../rfc/3464:433
|
|
const has8bit = false
|
|
const smtputf8 = false
|
|
if _, err := queue.Add(ctx, c.log, "", smtp.Path{}, rcptTo, has8bit, smtputf8, int64(len(buf)), nil, f, bufUTF8, true); err != nil {
|
|
return err
|
|
}
|
|
err = f.Close()
|
|
c.log.Check(err, "closing dsn file")
|
|
f = nil
|
|
return nil
|
|
}
|