feat(api): allow routing all email through fallback (#3509)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-17 04:16:08 +02:00
1 parent d564e01518
commit 2d8d130be1
5 files changed
+27 -3

No files matched your search

@@ -30,6 +30,16 @@ describe('DomainRoutedEmailProvider', () => {
expect(result).toBe(route === 'primary');
});
it('sends every address through the fallback provider when the domains are *', async () => {
const primary = {sendEmail: vi.fn().mockResolvedValue(true)};
const fallback = {sendEmail: vi.fn().mockResolvedValue(true)};
const provider = new DomainRoutedEmailProvider(primary, fallback, ['*']);
await provider.sendEmail(message('[email protected]'));
await provider.sendEmail(message('[email protected]'));
expect(fallback.sendEmail).toHaveBeenCalledTimes(2);
expect(primary.sendEmail).not.toHaveBeenCalled();
});
it('never reaches either provider for a bounced address', async () => {
const primary = {sendEmail: vi.fn().mockResolvedValue(true)};
const fallback = {sendEmail: vi.fn().mockResolvedValue(true)};
@@ -21,7 +21,7 @@ export class DomainRoutedEmailProvider implements IEmailProvider {
.slice(message.to.lastIndexOf('@') + 1)
.trim()
.toLowerCase();
const useFallback = this.fallbackDomains.has(domain);
const useFallback = this.fallbackDomains.has('*') || this.fallbackDomains.has(domain);
logger.debug({domain, provider: useFallback ? 'fallback' : 'primary'}, 'Routing email');
return (useFallback ? this.fallback : this.primary).sendEmail(message);
}