creaux / nestjs-mailgun

This is a simple wrapper of mailgun-js. It only comtemplates the send email and verify email functionalities, but later more it will be added. Just ping me or open pull request and contribute :)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NestJS Mailgun

NPM Version Package License NPM Downloads

Introduction

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 :)

Installation

npm install @nextnm/nestjs-mailgun

Usage

Importing module

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 {}

Interfaces

interface EmailOptions {
  from: string;
  to: string | string[];
  subject: string;
  text?: string;
  html?: string;
  template?: string;
  attachment?;
  'recipient-variables'?: {
    [email: string]: any;
  }
}

Calling Send Method

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);
  }

Calling Verify Method

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);
  }
}

Contributing

Contributions welcome! See Contributing.

Notes

This project is not endorsed by or affiliated with Mailgun.

Author

Nuno Carvalhão Site

License

Licensed under the MIT License - see the LICENSE file for details.

About

This is a simple wrapper of mailgun-js. It only comtemplates the send email and verify email functionalities, but later more it will be added. Just ping me or open pull request and contribute :)

License:MIT License


Languages

Language:TypeScript 100.0%