From 0b622368baa7c73731529e38ff0a5475a7a4328c Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 23 Jan 2024 11:01:08 +0100 Subject: [PATCH] #166: Add delivery status indication for messages This update introduces a new property, `isDelivered`, in the message struct to track if a message has been successfully sent or not. Additionally, this also includes a new helper function `IsDelivered` to easily retrieve the status. This feature enhances the tracking capabilities of outgoing messages across different client files. --- client_119.go | 1 + client_120.go | 1 + msg.go | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/client_119.go b/client_119.go index 3165a2d..df09e18 100644 --- a/client_119.go +++ b/client_119.go @@ -91,6 +91,7 @@ func (c *Client) Send(ml ...*Msg) error { errs = append(errs, se) continue } + m.isDelivered = true if err := w.Close(); err != nil { se := &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)} diff --git a/client_120.go b/client_120.go index 69eb5b3..1c0a5be 100644 --- a/client_120.go +++ b/client_120.go @@ -88,6 +88,7 @@ func (c *Client) Send(ml ...*Msg) (rerr error) { rerr = errors.Join(rerr, m.sendError) continue } + m.isDelivered = true if err := w.Close(); err != nil { m.sendError = &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)} diff --git a/msg.go b/msg.go index a3ce3da..c97fc01 100644 --- a/msg.go +++ b/msg.go @@ -94,6 +94,9 @@ type Msg struct { // genHeader is a slice of strings that the different generic mail Header fields genHeader map[Header][]string + // isDelivered signals if a message has been delivered or not + isDelivered bool + // middlewares is the list of middlewares to apply to the Msg before sending in FIFO order middlewares []Middleware @@ -507,6 +510,11 @@ func (m *Msg) SetUserAgent(a string) { m.SetGenHeader(HeaderXMailer, a) } +// IsDelivered will return true if the Msg has been successfully delivered +func (m *Msg) IsDelivered() bool { + return m.isDelivered +} + // RequestMDNTo adds the Disposition-Notification-To header to request a MDN from the receiving end // as described in RFC8098. It allows to provide a list recipient addresses. // Address validation is performed