import { Injectable } from '@nestjs/common';
import { MailerService } from '@nest-modules/mailer';
import * as config from 'config';

const mail= config.get('mail');

@Injectable()
export class EmailService {
    constructor(
        private readonly mailerService: MailerService
    ) { }
    // documenation : https://www.npmjs.com/package/@nest-modules/mailer

    async sendMail(toMail:string,subject:string,bodyText: string,htmlText:string){
        this.mailerService.sendMail({
            to: toMail, // sender address
            from: mail.fromMail, // list of receivers
            subject: subject, // Subject line
            text: bodyText, // plaintext body
            html: htmlText, // HTML body content
        })
        .then((res) => {
            console.log("==== here==res==", res)
        })
        .catch((err) => {
            console.log("=====err====", err);
        });
    }
}
