Skip to content

v0.2.7: MDNs and DSNs

Compare
Choose a tag to compare
@wneessen wneessen released this 12 Sep 08:06
· 1161 commits to main since this release
f4cdc61

This release adds support for requesting MDNs (RFC 8098) and DSNs (RFC 1891) to be delivered for outgoing mail messages. We've also added more test coverage.

MDNs

MDNs (Message Disposition Notification) allows you to request a - what is often referred to as - "read receipt". This is implemented via a message header and it's up the the recipients MUA to send out this notification to the sender.

Code example:

func main() {
	// [...]
	m := mail.NewMsg()
	if err := m.FromFormat("Max Tester", "[email protected]"); err != nil {
		panic(err)
	}
	if err := m.To("[email protected]"); err != nil {
		panic(err)
	}
	m.Subject("This is an example")
	if err := m.RequestMDNTo("[email protected]"); err != nil {
		fmt.Printf("failed to set MDN request header: %s", err)
	}
	// [...]
}

For MDNs we implement the same methods as for the To methods:

  • RequestMDNTo
  • RequestMDNToFormat
  • RequestMDNAddTo
  • RequestMDNAddToFormat

DSNs

DSNs (Delivery Status Notification) are an extension to the SMTP protocol and need to be supported by the sending server. The RFC for DSNs defines different parameters of which we've implemented the once which we think make most sense for go-mail:

  • The RET extension for the MAIL FROM command, to let the user specify if a DSN should contain the full mail (FULL) or only headers (HDRS) of the sent mail.
  • The NOTIFY extension that allows the user to request a DSN for the different types of allowed situations: NEVER, SUCCESS, FAILURE and DELAY

ENVID and ORCPT are currently not supported but might follow in a later relaese (please open an issue if you see usefulness in this).

Since DSNs are part of the SMTP protocol, these need to be enabled on the Client. We've added 3 ways to do so:

  • WithDSN: Which enables DSNs, sets the FULL Mail From Return Option and the SUCCESS and FAILURE Recipient Notify Options
  • WithDSNMailReturnType: which enables DSNs and allows the user to specify which type of Mail From Return Option is wanted
  • WithDSNRcptNotifyType: which enables DSNs and allows the user to specify which types of Recipient Notify Options are wanted

Code example:

func main() {
	// [...]
	cl, err := mail.NewClient("relay.example.net",
		mail.WithDSNMailReturnType(mail.DSNMailReturnFull),
		mail.WithDSNRcptNotifyType(mail.DSNRcptNotifyFailure, mail.DSNRcptNotifyDelay, mail.DSNRcptNotifySuccess))
	if err != nil {
		fmt.Printf("failed to create new client: %s\n", err)
		os.Exit(1)
	}
	// [...]
}

Noteworthy changes

  • 5bd3cec implements the MDN support
  • f4cdc61 implements the DSN support
  • da266bc adds better test coverage