Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Change required config in SES
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 9, 2020
1 parent fb081a2 commit d576cf0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/config/configuration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export interface Configuration {
email: {
name: string;
from: string;
ses?: boolean;
ses?: {
accessKeyId: string;
secretAccessKey: string;
region: string;
};
transport?: {
host: string;
port: number;
Expand Down
6 changes: 5 additions & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const configuration: Configuration = {
email: {
name: process.env.EMAIL_NAME ?? 'Staart',
from: process.env.EMAIL_FROM ?? '',
ses: !!process.env.EMAIL_SES,
ses: {
accessKeyId: process.env.EMAIL_SES_ACCESS_KEY_ID ?? '',
secretAccessKey: process.env.EMAIL_SES_SECRET_ACCESS_KEY ?? '',
region: process.env.EMAIL_SES_REGION ?? '',
},
transport: {
host: process.env.EMAIL_HOST ?? '',
port: int(process.env.EMAIL_PORT, 587),
Expand Down
11 changes: 8 additions & 3 deletions src/providers/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ export class MailService {

constructor(private configService: ConfigService) {
this.config = this.configService.get<Configuration['email']>('email');
console.log(this.config);
if (this.config.ses)
if (this.config.ses?.accessKeyId)
this.transport = nodemailer.createTransport({
SES: new SES({ apiVersion: '2010-12-01' }),
SES: new SES({
apiVersion: '2010-12-01',
accessKeyId: this.config.ses.accessKeyId,
secretAccessKey: this.config.ses.secretAccessKey,
region: this.config.ses.region,
}),
} as SESTransport.Options);
else this.transport = nodemailer.createTransport(this.config.transport);
}
Expand All @@ -48,6 +52,7 @@ export class MailService {
`Mail to ${options.to} failed, retrying (${error.retriesLeft} attempts left)`,
error.name,
);
console.log(error);
},
},
),
Expand Down

0 comments on commit d576cf0

Please sign in to comment.