Mailservice

This commit is contained in:
Bastian Wagner
2025-01-20 13:17:00 +01:00
parent abb703f592
commit add2fd0240
19 changed files with 3071 additions and 67 deletions

View File

@@ -0,0 +1,68 @@
import { MailerService } from "@nestjs-modules/mailer";
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { EmailEvent, LogService, LogType } from "../log/log.service";
@Injectable()
export class MailService {
constructor(
private mailserService: MailerService,
private readonly configService: ConfigService,
private readonly logService: LogService,
) {
}
async sendAccessGrantedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) {
this.mailserService.sendMail({
template: './access',
to: to,
from: this.configService.get<string>('MAILER_FROM'),
subject: 'Zugriff gewährt',
context: {
firstName,
systemName
}
}).then(v => {
this.logService.log(LogType.Mail, {
to,
success: true,
message: v.response,
type: EmailEvent.GrantSystemAccess
})
}).catch(e => {
this.logService.log(LogType.Mail, {
to,
success: false,
message: e.response,
type: EmailEvent.GrantSystemAccess
})
})
}
sendAccessRemovedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) {
this.mailserService.sendMail({
template: './access-removed',
to: to,
from: this.configService.get<string>('MAILER_FROM'),
subject: 'Zugriff entzogen',
context: {
firstName,
systemName
}
}).then(v => {
this.logService.log(LogType.Mail, {
to,
success: true,
message: v.response,
type: EmailEvent.RemoveSystemAccess
})
}).catch(e => {
this.logService.log(LogType.Mail, {
to,
success: false,
message: e.response,
type: EmailEvent.RemoveSystemAccess
})
})
}
}