nodemailer service final

This commit is contained in:
lemuel 2022-12-23 11:21:51 -06:00
parent 717e75d63e
commit c21edf9e97
2 changed files with 13 additions and 17 deletions

View File

@ -1,12 +1,7 @@
import { IsEmail, IsString } from 'class-validator';
export class NodemailerMessageDto {
@IsEmail()
email: string;
@IsString()
html: string;
@IsString()
subject: string;
}

View File

@ -5,7 +5,17 @@ import { NodemailerMessageDto } from './dto/nodemailer-message.dto';
@Injectable()
export class NodemailerService {
constructor(private configService: ConfigService) {}
private transporter;
constructor(private configService: ConfigService) {
this.transporter = nodemailer.createTransport({
service: this.configService.get<string>('NODEMAILER_SERVICE'),
auth: {
user: this.configService.get<string>('NODEMAILER_USER'),
pass: this.configService.get<string>('NODEMAILER_PASWORD'),
},
});
}
correoPasswordAdmin(operador, password: string) {
return `<h2>Estimad@ Responsable del programa PC Puma:</h2>
@ -111,20 +121,11 @@ export class NodemailerService {
`;
}
async sendEmail(message: NodemailerMessageDto) {
const transporter = nodemailer.createTransport({
service: this.configService.get<string>('NODEMAILER_SERVICE'),
auth: {
user: this.configService.get<string>('NODEMAILER_USER'),
pass: this.configService.get<string>('NODEMAILER_PASWORD'),
},
});
const res = await transporter.sendMail({
sendEmail(message: NodemailerMessageDto) {
return this.transporter.sendMail({
to: message.email,
subject: message.subject,
html: message.html,
});
return res;
}
}