@aws-sdk/client-ses
를 사용하여 이메일 템플릿을 관리하고 전송할 수 있습니다. 기본적으로 cli와 비슷하게 코드를 구성하면 되기 때문에 손쉽게 구현할 수 있습니다.
해당 내용은 Bulk 전송만 다룹니다.
@aws-sdk/client-ses
설치 및 세팅작업에 필요한 모듈을 설치해줍니다.
$ yarn add @aws-sdk/client-ses
aws configure
를 통해 셋팅한 cli환경처럼 생성자에 SESClient
를 만들어주는 코드를 작성합니다.
@Injectable()
export class EmailService {
readonly client: SESClient;
constructor() {
this.client = new SESClient({
region: 'ap-northeast-2',
credentials: {
secretAccessKey: config.awsSecretAccessKey,
accessKeyId: config.awsAccessKeyId,
},
});
}
}
우리는 Typescript를 사용하고 있기 때문에 SDK가 제공하는 Interface를 사용하여,
파라미터를 보다 안전하게 작성할 수 있습니다.
getSendEmailParam(
template: string,
destinations: **BulkEmailDestination**[],
defaultData: Record<string, string>,
): **SendBulkTemplatedEmailCommandInput** {
return {
Source: '박지호 <[email protected]>',
Template: template,
Destinations: destinations,
DefaultTemplateData: JSON.stringify(defaultData),
};
}
앞에서 만들었던 파라미터와 같습니다.