Skip to content
Open
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
39 changes: 26 additions & 13 deletions apps/api/src/services/SESService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,34 @@ ${breakLongLines(attachment.content, 76, true)}`;
const configurationSetName =
TRACKING_TOGGLE_ENABLED && !tracking ? SES_CONFIGURATION_SET_NO_TRACKING : SES_CONFIGURATION_SET;

// Send via SES
const response = await ses.sendRawEmail({
Destinations: destinations,
ConfigurationSetName: configurationSetName,
RawMessage: {
Data: new TextEncoder().encode(rawMessage),
},
Source: `${from.name} <${from.email}>`,
});
try {
// Send via SES
const response = await ses.sendRawEmail({
Destinations: destinations,
ConfigurationSetName: configurationSetName,
RawMessage: {
Data: new TextEncoder().encode(rawMessage),
},
Source: `${from.name} <${from.email}>`,
});

if (!response.MessageId) {
throw new Error('Could not send email');
}

if (!response.MessageId) {
throw new Error('Could not send email');
return {messageId: response.MessageId};
} catch (error) {
const originalMessage = error instanceof Error ? error.message : String(error);
const noTrackingMessage =
TRACKING_TOGGLE_ENABLED && !tracking
? ' If this was a preview/test email, verify SES_CONFIGURATION_SET_NO_TRACKING exists in AWS SES.'
: '';

throw new Error(
`Failed to send email via SES using configuration set "${configurationSetName}".${noTrackingMessage} Original error: ${originalMessage}`,
{cause: error},
);
}

return {messageId: response.MessageId};
}

/**
Expand Down