This is a simple wrapper of mailgun-js. It only supports sending and verifying emails, but later more will be added. Just ping me or open pull request and contribute :)
npm install @nextnm/nestjs-mailgun
import { MailgunModule } from '@nextnm/nestjs-mailgun';
@Module({
imports: [
MailgunModule.forRoot({
DOMAIN: '<Your Domain>',
API_KEY: '<Your API_KEY>',
HOST: '<Your Host>', // default: 'api.mailgun.net'. Note that if you are using the EU region the host should be set to 'api.eu.mailgun.net'
}),
],
providers: [],
exports: [],
})
export class YourModule {}
interface EmailOptions {
from: string;
to: string | string[];
subject: string;
text?: string;
html?: string;
template?: string;
attachment?;
'recipient-variables'?: {
[email: string]: any;
}
}
import { MailgunService } from '@nextnm/nestjs-mailgun';
import { EmailOptions } from '@nextnm/nestjs-mailgun'
@Injectable()
export class YourService {
constructor(private mailgunService: MailgunService) {
const options: EmailOptions = {
from: '',
to: '',
subject: '',
text: '',
html: '',
attachment:''
};
await this.mailgunService.sendEmail(options);
}
To check if an email is real or not.
import { MailgunService } from '@nextnm/nestjs-mailgun';
import { EmailOptions } from '@nextnm/nestjs-mailgun'
@Injectable()
export class YourService {
constructor(private mailgunService: MailgunService) {
await this.mailgunService.verifyEmail('next@examle.com);
}
}
Contributions welcome! See Contributing.
This project is not endorsed by or affiliated with Mailgun.
Nuno Carvalhão Site
Licensed under the MIT License - see the LICENSE file for details.