initial
This commit is contained in:
45
apps/api/src/mail/portal-mail.service.ts
Normal file
45
apps/api/src/mail/portal-mail.service.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
|
||||
@Injectable()
|
||||
export class PortalMailService {
|
||||
constructor(
|
||||
private readonly mailer: MailerService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
|
||||
async sendVerificationMail(to: string, token: string): Promise<void> {
|
||||
const url = `${this.publicWebUrl}/verify-email?token=${encodeURIComponent(token)}`;
|
||||
await this.mailer.sendMail({
|
||||
to,
|
||||
subject: 'LDAP Portal: E-Mail bestaetigen',
|
||||
html: `<p>Bitte bestaetige deine Registrierung:</p><p><a href="${url}">${url}</a></p>`,
|
||||
text: `Bitte bestaetige deine Registrierung: ${url}`,
|
||||
});
|
||||
}
|
||||
|
||||
async sendPasswordResetMail(to: string, token: string): Promise<void> {
|
||||
const url = `${this.publicWebUrl}/reset-password?token=${encodeURIComponent(token)}`;
|
||||
await this.mailer.sendMail({
|
||||
to,
|
||||
subject: 'LDAP Portal: Passwort zuruecksetzen',
|
||||
html: `<p>Du kannst dein Passwort ueber diesen Link zuruecksetzen:</p><p><a href="${url}">${url}</a></p>`,
|
||||
text: `Du kannst dein Passwort ueber diesen Link zuruecksetzen: ${url}`,
|
||||
});
|
||||
}
|
||||
|
||||
async sendEmailChangeMail(to: string, token: string): Promise<void> {
|
||||
const url = `${this.publicWebUrl}/account/email?token=${encodeURIComponent(token)}`;
|
||||
await this.mailer.sendMail({
|
||||
to,
|
||||
subject: 'LDAP Portal: neue E-Mail bestaetigen',
|
||||
html: `<p>Bitte bestaetige deine neue E-Mail-Adresse:</p><p><a href="${url}">${url}</a></p>`,
|
||||
text: `Bitte bestaetige deine neue E-Mail-Adresse: ${url}`,
|
||||
});
|
||||
}
|
||||
|
||||
private get publicWebUrl(): string {
|
||||
return this.config.get<string>('PUBLIC_WEB_URL') ?? 'http://localhost:4200';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user