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

Commit

Permalink
♻️ Use email config with Nodemailer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 22, 2020
1 parent dc79805 commit b4c6176
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
export default () => ({
email: {
name: 'Staart',
name: process.env.EMAIL_NAME ?? 'Staart',
from: process.env.EMAIL_FROM,
host: process.env.EMAIL_HOST,
port: process.env.EMAIL_PORT,
from: process.env.EMAIL_FROM,
password: process.env.EMAIL_PASSWORD,
secure: !!process.env.EMAIL_SECURE,
auth: {
user: process.env.EMAIL_USER ?? process.env.EMAIL_FROM,
pass: process.env.EMAIL_PASSWORD,
},
},
});
10 changes: 7 additions & 3 deletions src/modules/email/email.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export interface EmailConfig {
name: string;
host: string;
port: string;
from: string;
password: string;
host: string;
port: number;
secure: boolean;
auth: {
user: string;
pass: string;
};
}
7 changes: 5 additions & 2 deletions src/modules/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { EmailConfig } from './email.interface';
import nodemailer from 'nodemailer';
import Mail from 'nodemailer/lib/mailer';

@Injectable()
export class EmailService {
emailConfig: EmailConfig;
transport: Mail;

constructor(private configService: ConfigService) {
this.emailConfig = this.configService.get<EmailConfig>('email');
this.transport = nodemailer.createTransport(
this.configService.get<EmailConfig>('email'),
);
}
}

0 comments on commit b4c6176

Please sign in to comment.