Skip to content
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
9 changes: 6 additions & 3 deletions mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (m *Mail) Rcpt(to string) *smtp.SMTPError {
}

if action.Type == ActionTypeSyncResponse {
if action.Code == 250 {
m.RcptTo = append(m.RcptTo, to) // add RCPT
}

// note: SMTPError works for 200 as well
return &smtp.SMTPError{
Code: action.Code,
Expand All @@ -73,11 +77,10 @@ func (m *Mail) Rcpt(to string) *smtp.SMTPError {
})
}

// add RCPT
// reached for async actions
m.RcptTo = append(m.RcptTo, to)

return nil // OK response

return nil // OK Response
}

func (m *Mail) Complete() error {
Expand Down
43 changes: 42 additions & 1 deletion mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,47 @@ func TestProcessMailComplaint(t *testing.T) {
assert.Equal(t, 0, complaintDelay)
}

func TestMailWithOneRcptOkayOtherFail(t *testing.T) {

mail := NewMail()

mail.MailFrom = "bounces@example.com"

err := mail.Rcpt("accept@localhost")
assert.Equal(t, 250, err.Code)

err = mail.Rcpt("busy@localhost")
assert.Equal(t, 450, err.Code)

assert.Equal(t, []string{"accept@localhost"}, mail.RcptTo)

smtpErr := mail.Complete()
assert.Nil(t, smtpErr)

}

func TestMailWithOneRcptOkayOneFailAndOtherAsync(t *testing.T) {

mail := NewMail()

mail.MailFrom = "bounces@example.com"

err := mail.Rcpt("accept@localhost")
assert.Equal(t, 250, err.Code)

err = mail.Rcpt("busy@localhost")
assert.Equal(t, 450, err.Code)

err = mail.Rcpt("missing+async@localhost")
assert.Nil(t, err)

assert.Equal(t, []string{"accept@localhost", "missing+async@localhost"}, mail.RcptTo)

smtpErr := mail.Complete()
assert.Nil(t, smtpErr)

}

func TestSplitAddress(t *testing.T) {

tests := []struct {
Expand Down Expand Up @@ -165,4 +206,4 @@ func TestSendMailhandler(t *testing.T) {
assert.Equal(t, "simulator@localhost", fromGot)
assert.Equal(t, []string{"bounces@example.com"}, toGot)

}
}