feat(mail): add Resend API transport
This commit is contained in:
1 parent
1aa7a9feaf
commit
c85b642d32
13 files changed
+1387
-63
No files matched your search
@@ -42,16 +42,30 @@ const (
|
||||
// a message ID. It does not mean the message was delivered or read.
|
||||
MailOutcomeAccepted MailOutcome = "accepted"
|
||||
|
||||
// MailOutcomeRejected means the provider answered and refused the
|
||||
// request; it did not take the message. Rejection says why.
|
||||
// MailOutcomeRejected means the provider did not take the message: either
|
||||
// it answered and refused the request, or the transport failed before the
|
||||
// request was completely written (DNS, connect, or TLS failure), so no
|
||||
// complete request reached the provider. Rejection says why; the second case is
|
||||
// always MailRejectionTemporary.
|
||||
MailOutcomeRejected MailOutcome = "rejected"
|
||||
|
||||
// MailOutcomeUnknown means the request may have reached the provider but
|
||||
// no conclusive answer came back, for example a timeout or a connection
|
||||
// lost after the request was written. The message may or may not have
|
||||
// been accepted (delivery_uncertain). It is not a failure: a retry must
|
||||
// reuse the same IdempotencyKey so a provider that supports keys can
|
||||
// deduplicate it.
|
||||
// no conclusive answer came back, for example a timeout, a connection
|
||||
// lost after the request was written, or a provider error raised while
|
||||
// handling it. The message may or may not have been accepted
|
||||
// (delivery_uncertain). It is not a "not sent" result: a retry must reuse
|
||||
// the same IdempotencyKey and the same content so a provider that
|
||||
// supports keys can deduplicate it. Deduplication has a window (24 hours
|
||||
// for Resend); after it a retry may send the message twice, so the
|
||||
// delivery layer must stop retrying and escalate to an operator instead.
|
||||
//
|
||||
// ProviderCode may name the reason. With Resend,
|
||||
// "concurrent_idempotent_requests" means another request with the same
|
||||
// key is still in progress: retry later with the same key. And
|
||||
// "invalid_idempotent_request" means the key was already used with
|
||||
// another body, so an earlier request under it may have been accepted;
|
||||
// repeating cannot succeed and a new key could send the message twice, so
|
||||
// the delivery layer must stop and escalate.
|
||||
MailOutcomeUnknown MailOutcome = "unknown"
|
||||
)
|
||||
|
||||
@@ -77,11 +91,24 @@ const (
|
||||
// used up; retrying before the quota resets cannot help.
|
||||
MailRejectionQuotaExhausted MailRejection = "quota_exhausted"
|
||||
|
||||
// MailRejectionTemporary means a transient provider-side refusal, such as
|
||||
// a 5xx answer or an SMTP 4xx reply, that a later attempt may overcome.
|
||||
// MailRejectionTemporary means a transient condition that a later attempt
|
||||
// may overcome: a provider-side refusal, such as a 5xx answer or an SMTP
|
||||
// 4xx reply, or a failure before the request was completely written. In
|
||||
// the second case no complete request reached the provider, so a retry
|
||||
// cannot duplicate the message.
|
||||
MailRejectionTemporary MailRejection = "temporary"
|
||||
)
|
||||
|
||||
// MailProviderCode is the provider's machine-readable error name for a
|
||||
// rejected or unknown attempt, for example Resend's
|
||||
// "invalid_idempotent_request" or "daily_quota_exceeded". A transport sets it only to a name from its own
|
||||
// fixed list of documented provider names and leaves it empty for anything
|
||||
// else, so it never carries free text from the provider and is safe to log,
|
||||
// store, and use as a metric label. Retry decisions follow Outcome and
|
||||
// Rejection; the code adds operator detail, such as telling a wrong API key
|
||||
// from a malformed request, or an idempotency key reused with another body.
|
||||
type MailProviderCode string
|
||||
|
||||
// OutgoingMail is one rendered message. The sender address comes from the
|
||||
// transport configuration (EMAIL_FROM), so usecases and templates never choose
|
||||
// or depend on it, nor on the provider.
|
||||
@@ -98,7 +125,8 @@ type OutgoingMail struct {
|
||||
// IdempotencyKey is stable for one logical delivery across every retry,
|
||||
// for example "email_verification/<token id>". A transport that supports
|
||||
// provider-side deduplication sends it; others ignore it. It must not
|
||||
// contain personal data.
|
||||
// contain personal data. The provider keeps it only for a limited window
|
||||
// (24 hours for Resend); see MailOutcomeUnknown.
|
||||
IdempotencyKey string
|
||||
}
|
||||
|
||||
@@ -158,8 +186,15 @@ type SendResult struct {
|
||||
// Rejection is set only for MailOutcomeRejected.
|
||||
Rejection MailRejection
|
||||
|
||||
// RetryAfter is the provider's requested wait for a rejected attempt, or
|
||||
// zero when the provider gave none.
|
||||
// ProviderCode is set only for MailOutcomeRejected and MailOutcomeUnknown,
|
||||
// and only when the provider answered with a documented error name; see
|
||||
// MailProviderCode.
|
||||
ProviderCode MailProviderCode
|
||||
|
||||
// RetryAfter is the wait before the next attempt for a rejected or
|
||||
// unknown result: the provider's own hint (for example Retry-After), or a
|
||||
// wait the transport derived from documented provider rules (for example
|
||||
// the next daily quota reset). It is zero when there is neither.
|
||||
RetryAfter time.Duration
|
||||
}
|
||||
|
||||
@@ -172,7 +207,10 @@ type SendResult struct {
|
||||
// wraps ErrMailChannelUnavailable when no transport is active,
|
||||
// ErrInvalidOutgoingMail for an invalid message, or the context error when
|
||||
// ctx ended before the request was sent. The returned SendResult is then
|
||||
// zero and must be ignored.
|
||||
// zero and must be ignored. A failure to reach the provider before the
|
||||
// request was written while ctx is still active is not an error: it is
|
||||
// MailOutcomeRejected with MailRejectionTemporary. A failure after the request
|
||||
// may have been written is MailOutcomeUnknown.
|
||||
//
|
||||
// Errors and logs never include recipients, subjects, bodies, credentials, or
|
||||
// raw provider responses.
|
||||
|
||||
Reference in new issue
Block a user