Add contact, upgrade versions, add docs
This commit is contained in:
36
src/email/email.service.ts
Normal file
36
src/email/email.service.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import Mailgun from 'mailgun.js';
|
||||
import * as formdata from 'form-data';
|
||||
import { IMailgunClient } from 'mailgun.js/Interfaces';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class EmailService {
|
||||
private readonly mailgun: IMailgunClient | undefined;
|
||||
private static readonly emailFromDomain = 'hello.hooli.co';
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
const mailgun = new Mailgun(formdata);
|
||||
const hooliKey = this.configService.get<string>('mailgun.hooliKey');
|
||||
if (!hooliKey) {
|
||||
return;
|
||||
}
|
||||
this.mailgun = mailgun.client({
|
||||
username: 'api',
|
||||
key: hooliKey,
|
||||
});
|
||||
}
|
||||
|
||||
async sendEmail(to: string[], subject: string, text: string) {
|
||||
if (!this.mailgun) {
|
||||
return;
|
||||
}
|
||||
return this.mailgun.messages.create(EmailService.emailFromDomain, {
|
||||
from: `HooliMail <hooli-mail@${EmailService.emailFromDomain}>`,
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
html: text,
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user