new node.js impl., removed old stuff
This commit is contained in:
52
email-worker-nodejs/ses.ts
Normal file
52
email-worker-nodejs/ses.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* SES operations handler
|
||||
*
|
||||
* Only used for:
|
||||
* - Sending OOO replies to external addresses
|
||||
* - Forwarding to external addresses
|
||||
*/
|
||||
|
||||
import {
|
||||
SESClient,
|
||||
SendRawEmailCommand,
|
||||
} from '@aws-sdk/client-ses';
|
||||
import { config } from '../config.js';
|
||||
import { log } from '../logger.js';
|
||||
|
||||
export class SESHandler {
|
||||
private client: SESClient;
|
||||
|
||||
constructor() {
|
||||
this.client = new SESClient({ region: config.awsRegion });
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a raw MIME message via SES.
|
||||
* Returns true on success, false on failure (never throws).
|
||||
*/
|
||||
async sendRawEmail(
|
||||
source: string,
|
||||
destination: string,
|
||||
rawMessage: Buffer,
|
||||
workerName: string,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
await this.client.send(
|
||||
new SendRawEmailCommand({
|
||||
Source: source,
|
||||
Destinations: [destination],
|
||||
RawMessage: { Data: rawMessage },
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
const code = err.name ?? err.Code ?? 'Unknown';
|
||||
log(
|
||||
`⚠ SES send failed to ${destination} (${code}): ${err.message ?? err}`,
|
||||
'ERROR',
|
||||
workerName,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user