ultisuite-backend/internal/mail/smtp/retry.go
R3D347HR4Y 4eadb91a64 Enhance mail API with rate limiting, idempotency, and attachment management
- Added rate limiting for outbound email sends to prevent abuse, implemented in `internal/api/mail/sendguard`.
- Introduced idempotency key support for email sending to avoid duplicate submissions.
- Enhanced attachment handling with new limits and validation in `internal/api/mail/limits`.
- Updated outbox processing to include retry logic and circuit breaker for SMTP failures.
- Improved HTML sanitization for email content to enhance security.
- Added unit tests for new features, ensuring robust functionality and error handling.
- Updated configuration options in `.env.example` for new mail settings.
2026-05-22 17:19:16 +02:00

29 lines
571 B
Go

package smtp
import "time"
const (
DefaultMaxOutboxRetries = 8
maxRetryDelay = time.Hour
baseRetryDelay = 30 * time.Second
)
// OutboxRetryDelay returns exponential backoff before the next send attempt.
func OutboxRetryDelay(retryCount int) time.Duration {
if retryCount <= 0 {
return baseRetryDelay
}
delay := baseRetryDelay
for i := 0; i < retryCount && delay < maxRetryDelay; i++ {
if delay > maxRetryDelay/2 {
delay = maxRetryDelay
break
}
delay *= 2
}
if delay > maxRetryDelay {
return maxRetryDelay
}
return delay
}