default from email

This commit is contained in:
Evert Prants 2022-09-09 17:51:15 +03:00
parent 42d0f302bf
commit 3b3fa2a7de
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 5 additions and 3 deletions

View File

@ -1,9 +1,9 @@
import { Provider } from '@nestjs/common'; import { FactoryProvider } from '@nestjs/common';
import * as nodemailer from 'nodemailer'; import * as nodemailer from 'nodemailer';
import { SMTPConfiguration } from 'src/modules/config/config.interfaces'; import { SMTPConfiguration } from 'src/modules/config/config.interfaces';
import { ConfigurationService } from 'src/modules/config/config.service'; import { ConfigurationService } from 'src/modules/config/config.service';
export const emailProviders: Provider<any>[] = [ export const emailProviders: FactoryProvider<nodemailer.Transporter>[] = [
{ {
provide: 'EMAIL_TRANSPORT', provide: 'EMAIL_TRANSPORT',
useFactory: async (config: ConfigurationService) => useFactory: async (config: ConfigurationService) =>

View File

@ -1,5 +1,6 @@
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import * as nodemailer from 'nodemailer'; import * as nodemailer from 'nodemailer';
import { ConfigurationService } from 'src/modules/config/config.service';
import { EmailTemplate } from './email.template'; import { EmailTemplate } from './email.template';
@Injectable() @Injectable()
@ -7,6 +8,7 @@ export class EmailService {
constructor( constructor(
@Inject('EMAIL_TRANSPORT') @Inject('EMAIL_TRANSPORT')
private transport: nodemailer.Transporter, private transport: nodemailer.Transporter,
private config: ConfigurationService,
) {} ) {}
public async sendEmail( public async sendEmail(
@ -14,7 +16,7 @@ export class EmailService {
subject: string, subject: string,
text: string, text: string,
html?: string, html?: string,
from = 'no-reply@icynet.eu', from = this.config.get<string>('email.from'),
): Promise<any> { ): Promise<any> {
return this.transport.sendMail({ return this.transport.sendMail({
to, to,