JSPM

  • Created
  • Published
  • Downloads 2339
  • Score
    100M100P100Q117489F
  • License MIT

NestJS provider for sending emails with mailgun

Package Exports

  • nestjs-mailgun
  • nestjs-mailgun/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-mailgun) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

yarn add nestjs-mailgun

Usage

Importing module

import { MailgunModule } from 'nestjs-mailgun';
@Module({
  imports: [
    MailgunModule.forRoot({
      DOMAIN: '<Your Domain>',
      API_KEY: '<Your API_KEY>',
      // default: 'api.mailgun.net'. Note that if you are using the EU region the host should be set to 'api.eu.mailgun.net'
      HOST: '<Your Host>',
    }),
  ],
  providers: [],
  exports: [],
})
export class YourModule {}

Importing module Async

import { MailgunModule } from 'nestjs-mailgun';
@Module({
  imports: [
    MailgunModule.forAsyncRoot({
      imports: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        return {
          DOMAIN: configService.get('<Your Domain>'),
          API_KEY: configService.get('<Your API_KEY>'),
           // default: 'api.mailgun.net'.
           // Note that if you are using the EU region the host should be set to 'api.eu.mailgun.net'
          HOST: configService.get('<Your Host>'),
        };
      },
      inject: [ConfigService]
    }),
  ],
  providers: [],
  exports: [],
})
export class YourModule {}

Interfaces

interface EmailOptions {
  from: string;
  to: string | string[];
  subject: string;
  text?: string;
  html?: string;
  template?: string;
  attachment?;
  'h:X-Mailgun-Variables'?: string;
}

Calling Send Method

import { MailgunService } from 'nestjs-mailgun';
import { EmailOptions } from '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);
  }

Calling Verify Method

To check if an email is real or not.

import { MailgunService } from 'nestjs-mailgun';
import { EmailOptions } from '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

Stanislav V Vyalyi Site Nuno Carvalhão Site

License

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