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

81 lines
2.7 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 {
2022-07-25 04:38:48 +00:00
constructor(private mailService: MailerService) {}
2022-07-16 00:36:02 +00:00
2022-07-25 04:38:48 +00:00
@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;
}
2022-07-16 00:36:02 +00:00
@MessagePattern({ cmd: 'html' })
async postHTMLEmail(@Payload() user: any) {
const url = "http://localhost:3000/";
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',
2022-07-17 00:08:10 +00:00
cid: 'logo' //my mistake was putting "cid:logo@cid" here!
}
]
});
return response;
}
@MessagePattern({ cmd: 'emailCreateUserAdminCommunity' })
async emailCreateUserAdmin(@Payload() user: any) {
const url = "http://localhost:3000/";
const image = "images/email.png";
const logo = "images/Logo Katoikia.svg";
var response = await this.mailService.sendMail({
to: user["email"],
from: "mbonilla.guti@gmail.com",
subject: 'Usuario registrado',
2022-07-26 23:07:12 +00:00
template: 'emailCreateUserAdminCommunity',
context: {
name: user["name"],
password: user["password"],
date_entry: user["date_entry"],
email: user["email"],
community_name: user['community_name'],
url
},
attachments: [
{
filename: 'email.png',
path: __dirname + '/mails/images/email.png',
cid: 'image_email' //my mistake was putting "cid:logo@cid" here!
},
{
filename: 'Logo Katoikia.svg',
path: __dirname + '/mails/images/Logo Katoikia.svg',
2022-07-26 23:07:12 +00:00
cid: 'logoKatoikia' //my mistake was putting "cid:logo@cid" here!
}
2022-07-17 00:08:10 +00:00
]
2022-07-16 00:36:02 +00:00
});
return response;
}
}