File

src/common/mail.service.ts

Index

Methods

Constructor

constructor(mailerService: MailerService)
Parameters :
Name Type Optional
mailerService MailerService No

Methods

Async sendMail
sendMail(to: string, cc: string, subject: string, mailText: string | null, html: string | null)
Parameters :
Name Type Optional Default value
to string No
cc string No
subject string No
mailText string | null No
html string | null No null
Returns : any
import { MailerService } from "@nestjs-modules/mailer";
import { Injectable, Logger } from "@nestjs/common";

@Injectable()
export class MailService {
  constructor(private readonly mailerService: MailerService) {}

  async sendMail(
    to: string,
    cc: string,
    subject: string,
    mailText: string | null,
    html: string | null = null,
  ) {
    try {
      Logger.log("Sending email to: " + to, "Utils.sendMail");
      await this.mailerService.sendMail({
        to,
        ...(cc && { cc }),
        ...(subject && { subject }),
        ...(html && { html }),
        ...(mailText && { mailText }),
      });
    } catch (error) {
      Logger.error("Failed sending email to: " + to, "MailService.sendMail");
      Logger.error(error, "MailService.sendMail");
    }
  }
}

results matching ""

    No results matching ""