katoikia-app/servicio-notificaciones/src/email.controller.ts

47 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-07-16 00:36:02 +00:00
import { Controller, Get, Query } from '@nestjs/common';
import { MessagePattern, Payload } from '@nestjs/microservices';
import { MailerService } from '@nestjs-modules/mailer';
import { User } from './user/user.entity';
@Controller()
export class EmailController {
constructor(private mailService: MailerService) { }
@MessagePattern({ cmd: 'sendMail' })
sendMail(@Payload() toEmail: string) {
var response = this.mailService.sendMail({
to: toEmail["email"],
from: "mbonilla.guti@gmail.com",
subject: 'Plain Text Email ✔',
text: 'Welcome NestJS Email Sending Tutorial',
});
return response;
}
@MessagePattern({ cmd: 'html' })
async postHTMLEmail(@Payload() user: any) {
const url = "http://localhost:3000/";
2022-07-17 00:08:10 +00:00
const image = "images/email.ong";
2022-07-16 00:36:02 +00:00
var response = await this.mailService.sendMail({
to: user["email"],
from: "mbonilla.guti@gmail.com",
subject: 'HTML Dynamic Template',
2022-07-17 00:08:10 +00:00
template: 'templateEmail',
2022-07-16 00:36:02 +00:00
context: {
name: user["name"],
2022-07-17 00:08:10 +00:00
url
2022-07-16 00:36:02 +00:00
},
2022-07-17 00:08:10 +00:00
attachments: [
{
filename: 'email.png',
path: __dirname +'/mails/images/email.png',
cid: 'logo' //my mistake was putting "cid:logo@cid" here!
}
]
2022-07-16 00:36:02 +00:00
});
return response;
}
}