-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathses.connector.ts
More file actions
64 lines (56 loc) · 1.46 KB
/
ses.connector.ts
File metadata and controls
64 lines (56 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses';
interface EmailOptions {
html?: string;
}
interface MessageBody {
Text: {
Data: string;
};
Html?: {
Data: string;
};
}
class SESConnector {
private client: SESClient;
constructor() {
// Use the SDK's default credential/provider chain.
this.client = new SESClient({ region: 'us-east-2' });
}
async sendEmail(
to: string,
subject: string,
body: string,
options?: EmailOptions
): Promise<boolean> {
try {
const bodyConfig: MessageBody = {
Text: {
Data: body,
},
};
if (options?.html) {
bodyConfig.Html = {
Data: options.html,
};
}
const params = {
Source: `no-reply@${process.env.EMAIL_DOMAIN}`,
Destination: {
ToAddresses: [to],
},
Message: {
Subject: {
Data: subject,
},
Body: bodyConfig,
},
};
const res = await this.client.send(new SendEmailCommand(params));
return !!res.MessageId;
} catch (error) {
throw error;
}
}
}
const sesConnector = new SESConnector();
export default sesConnector;