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 {}
import { MailgunModule } from '@nextnm/nestjs-mailgun';
@Module({
imports: [
MailgunModule.forAsyncRoot({
useFactory: async () => {
return {
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?;
'h:X-Mailgun-Variables'?: string;
}
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:''
'h:X-Mailgun-Variables': '{"key":"value"}'
};
await this.mailgunService.sendEmail(options);
// OR can use the class
const email = new MailgunEmailModel('from', 'to', 'subject', 'text', 'html', 'template','attachment', { key: 'value' });
await this.mailgunService.sendEmail(email);
}
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.validateEmail('[email protected]');
}
}
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.