1.1.3 • Published 4 years ago

@gkampitakis/email-client v1.1.3

Weekly downloads
30
License
ISC
Repository
github
Last release
4 years ago

Email Client

Codecov Coverage Build Status semantic-release

A library written in typescript using known email clients for sending emails. It has built in support for compiling templates and sending html in the email.

Changelog

CHANGELOG.md

Usage

Configuration of client

import { EmailClient } from '@gkampitakis/email-client';

const client = new EmailClient({
	transporter: 'sendgrid', // Supported 'sendgrid', 'mailgun', 'postmark', 'mandrill' ,'aws'
	apik_key: '', //Your api key depending on each client provider
	templateDir: __dirname + '/path/to/your/email/templates'
	//... any other provider specific configuration
});

More specific configs for some transporters

{
	"api_key":<apiKey>,
	"secret":<secret>,
	"region:"<region>
}
{
	"api_key":<apiKey>,
	"domain":<domain>
}

Send an email

client.send({
	from: 'mock@email.com',
	to: 'test@email.com',
	text: 'Hello World'
});

API

  • from string
  • to string or string []
  • cc string or string []
  • bcc string or string []
  • text string
  • subject string
  • template string the filename of the html template you want to use
  • data object an object containing the data that the template is going to be compiled with
  • subject string
  • any other transporter specific field
  • attachments
    [
    	{
    		"name": "myfilte.txt",
    		"path": __dirname + "/path/to/file"
    	}
    ]

Email Client Methods

const client = new EmailClient({...});

/*Exposes handlebars configuration method*/
client.configureHandlebars({
	configure:()=>void,
	helpers:[]
});

/*Set a new transporter*/
client.setTransporter('sendgrid',{...});

/*Get the transporter*/
client.getTransporter();

/*Set path for the templates*/
client.setTemplates('/path/to/new/templates');

Dependencies

Suporrted Templates

  • mjml
  • handlebars

Supported Clients

  • mailgun
  • postmark
  • mandrill This transporter is not yet properly tested!!
  • sendgrid
  • AwsSES

Author and Maintainer

Georgios Kampitakis

For any issues.