Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delivery status indication for messages #167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client_119.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
1 change: 1 addition & 0 deletions client_120.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
7 changes: 6 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ func TestClient_DialSendClose(t *testing.T) {
if err := c.Close(); err != nil {
t.Errorf("Close() failed: %s", err)
}
if !m.IsDelivered() {
t.Errorf("message should be delivered but is indicated no to")
}
}

// TestClient_DialAndSendWithContext tests the DialAndSendWithContext() method of Client
Expand Down Expand Up @@ -1134,7 +1137,9 @@ func TestClient_DialAndSendWithContext_withSendError(t *testing.T) {
}
if se.IsTemp() {
t.Errorf("expected permanent error but IsTemp() returned true")
return
}
if m.IsDelivered() {
t.Errorf("message is indicated to be delivered but shouldn't")
}
}

Expand Down
8 changes: 8 additions & 0 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading