mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-09 15:32:54 +01:00
Merge pull request #167 from wneessen/feature/166_no-easy-way-to-determine-if-e-mail-was-send
Add delivery status indication for messages
This commit is contained in:
commit
99dd296486
4 changed files with 16 additions and 1 deletions
|
@ -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)}
|
||||
|
|
|
@ -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)}
|
||||
|
|
|
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
8
msg.go
8
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
|
||||
|
|
Loading…
Reference in a new issue