-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate transactional email from Bento to AutoSend #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,40 @@ | ||
| import { | ||
| BENTO_DEFAULT_FROM, | ||
| BENTO_REPLY_TO, | ||
| BENTO_PUBLISHABLE_KEY, | ||
| BENTO_SECRET_KEY, | ||
| BENTO_SITE_UUID | ||
| } from '$env/static/private'; | ||
| import { BentoClient } from '$lib/server/bento.js'; | ||
| import { AUTOSEND_API_KEY, AUTOSEND_DEFAULT_FROM, AUTOSEND_REPLY_TO } from '$env/static/private'; | ||
| import type { EmailAddress } from 'autosendjs'; | ||
| import { AutosendClient } from '$lib/server/autosend.js'; | ||
| import { EmailService } from '$lib/features/email/server/email.service.js'; | ||
|
|
||
| const bentoClient = new BentoClient({ | ||
| publishableKey: BENTO_PUBLISHABLE_KEY, | ||
| secretKey: BENTO_SECRET_KEY, | ||
| siteUuid: BENTO_SITE_UUID | ||
| const autosendClient = new AutosendClient({ | ||
| apiKey: AUTOSEND_API_KEY | ||
| }); | ||
|
|
||
| const defaultFrom = BENTO_DEFAULT_FROM || 'EmitKit <noreply@emitkit.com>'; | ||
| const defaultReplyTo = BENTO_REPLY_TO || 'support@emitkit.com'; | ||
| /** | ||
| * Parse an "Name <email>" or bare "email" string into a structured EmailAddress. | ||
| * Autosend requires a structured object for from/replyTo; passing an RFC-5322 | ||
| * string causes silent send failures. | ||
| */ | ||
| function parseEmailAddress(value: string | undefined, fallback: EmailAddress): EmailAddress { | ||
| if (!value) return fallback; | ||
| const match = value.match(/^\s*(.*?)\s*<\s*([^>]+)\s*>\s*$/); | ||
| if (match) { | ||
| const [, name, email] = match; | ||
| return name ? { email, name } : { email }; | ||
| } | ||
| return { email: value.trim() }; | ||
| } | ||
|
Comment on lines
+15
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden env email parsing to avoid invalid defaults reaching Autosend At Line 16 and Line 22, whitespace-only env values can produce Suggested patch function parseEmailAddress(value: string | undefined, fallback: EmailAddress): EmailAddress {
- if (!value) return fallback;
- const match = value.match(/^\s*(.*?)\s*<\s*([^>]+)\s*>\s*$/);
+ const normalized = value?.trim();
+ if (!normalized) return fallback;
+ const match = normalized.match(/^\s*(.*?)\s*<\s*([^>]+)\s*>\s*$/);
if (match) {
- const [, name, email] = match;
- return name ? { email, name } : { email };
+ const [, rawName, rawEmail] = match;
+ const email = rawEmail.trim();
+ if (!email) return fallback;
+ const name = rawName.trim();
+ return name ? { email, name } : { email };
}
- return { email: value.trim() };
+ return normalized ? { email: normalized } : fallback;
}Also applies to: 25-29 🤖 Prompt for AI Agents |
||
|
|
||
| const defaultFrom = parseEmailAddress(AUTOSEND_DEFAULT_FROM, { | ||
| email: 'noreply@emitkit.com', | ||
| name: 'EmitKit' | ||
| }); | ||
| const defaultReplyTo = parseEmailAddress(AUTOSEND_REPLY_TO, { email: 'support@emitkit.com' }); | ||
|
|
||
| export const emailService = new EmailService({ | ||
| bentoClient, | ||
| autosendClient, | ||
| defaultFrom, | ||
| defaultReplyTo | ||
| }); | ||
|
|
||
| export { bentoClient }; | ||
| export { autosendClient }; | ||
|
|
||
| export { default as OTPEmail } from '../components/otp-email.svelte'; | ||
| export { default as WelcomeEmail } from '../components/welcome-email.svelte'; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't silently skip sends when Autosend is misconfigured outside local preview/dev flows.
These branches turn a required provider misconfiguration into
{ skipped: true }.src/lib/server/auth.ts:101-128awaitsemailService.sendEmail()but never checksskipped, so password-reset mail can be dropped while the auth operation still records success. Throw here in non-dev (or fail fast during startup) and keep the skip path only for explicitly local preview scenarios.Also applies to: 116-122
🤖 Prompt for AI Agents