All Projects â†’ bahdcoder â†’ friendly-mail

bahdcoder / friendly-mail

Licence: MIT license
📩 Mail provider for elegantly sending emails in node js.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to friendly-mail

Sendgrid Mailer
Provides Sendgrid integration for Symfony Mailer
Stars: ✭ 24 (-40%)
Mutual labels:  mailer
Yii2 Swiftmailer
Yii 2 swiftmailer extension.
Stars: ✭ 109 (+172.5%)
Mutual labels:  mailer
stampie-bundle
stampie.github.io/
Stars: ✭ 26 (-35%)
Mutual labels:  mailer
Mailgun Mailer
Provides Mailgun integration for Symfony Mailer
Stars: ✭ 41 (+2.5%)
Mutual labels:  mailer
Gpg Mailer
GnuPG-encrypted emails made easy
Stars: ✭ 93 (+132.5%)
Mutual labels:  mailer
Fake Mailer
Send Mail Anonymously with this Script
Stars: ✭ 126 (+215%)
Mutual labels:  mailer
Resque mailer
Rails plugin for sending asynchronous email with ActionMailer and Resque
Stars: ✭ 612 (+1430%)
Mutual labels:  mailer
mailer-plugin
This plugin allows you to configure email notifications for build results
Stars: ✭ 35 (-12.5%)
Mutual labels:  mailer
Swiftmailer
Comprehensive mailing tools for PHP
Stars: ✭ 9,503 (+23657.5%)
Mutual labels:  mailer
yii2-symfonymailer
Yii 2 Symfony mailer extension.
Stars: ✭ 29 (-27.5%)
Mutual labels:  mailer
Mailer
A lightweight PHP SMTP mail sender
Stars: ✭ 53 (+32.5%)
Mutual labels:  mailer
Pentydesktopassistant
Penty is a small Desktop Assistant programmed with JS and Python as its backend and HTML and CSS as its front. Took just over a month to create v1.0. It has a few features, like an in-built gMail sender and a quick-open browser.
Stars: ✭ 80 (+100%)
Mutual labels:  mailer
Magento 2 Smtp
Magento 2 SMTP Extension helps the owner of store simply install SMTP (Simple Mail Transfer Protocol) server which transmits the messages into codes or numbers.
Stars: ✭ 228 (+470%)
Mutual labels:  mailer
Rems For Organisations
Resources and Event Management System for small organisations and clubs. Mailers, Certificate Generation and much more 🎓🔗
Stars: ✭ 41 (+2.5%)
Mutual labels:  mailer
django-yubin
Send e-mails asyncronously using cron
Stars: ✭ 44 (+10%)
Mutual labels:  mailer
Lettre
a mailer library for Rust
Stars: ✭ 713 (+1682.5%)
Mutual labels:  mailer
Swiftmailer Bundle
Symfony Swiftmailer Bundle
Stars: ✭ 1,558 (+3795%)
Mutual labels:  mailer
quartz-mailer
A library to get started in sending and receiving emails from and to your Crystal application
Stars: ✭ 23 (-42.5%)
Mutual labels:  mailer
Log-mailer
Log mailer is a program I made to email log files.
Stars: ✭ 46 (+15%)
Mutual labels:  mailer
Play Mailer
Play mailer plugin
Stars: ✭ 243 (+507.5%)
Mutual labels:  mailer

Friendly Mail 📩

Build Status

Elegant mail sender for node js.

Friendly Mail is simple, clean, and modern and easy to use email sending package for Nodejs built on top of nodemailer and uses driver implementations from Adonis Mail.

Supported mail drivers: smtp, mailgun, amazon-ses, sparkpost, ethereal

Installation

You can install the package using npm or yarn

npm install --save friendly-mail
# Using yarn
yarn add friendly-mail

Create a mail configuration file

To configure what drivers you'll be using to send emails, view engines and more, you need to generate a mail.config.js file in your project's root.

# Using npm
npx friendlymail init

# Using yarn
yarn friendlymail init

Setting it up

Here's an example of the configuration:

module.exports = {
    /*
    |--------------------------------------------------------------------------
    | Connection
    |--------------------------------------------------------------------------
    |
    | Connection to be used for sending emails. Each connection needs to
    | define a driver too.
    |
    */
    connection: process.env.MAIL_CONNECTION || 'smtp',

    /*
    |--------------------------------------------------------------------------
    | Views
    |--------------------------------------------------------------------------
    |
    | This configuration defines the folder in which all emails are stored.
    | If it is not defined, /mails is used as default.
    |
    */
    views: '/mails',

    /*
    |--------------------------------------------------------------------------
    | View engine
    |--------------------------------------------------------------------------
    |
    | This is the view engine that should be used. The currently supported are:
    | handlebars, edge
    |
    */
    viewEngine: 'handlebars',

    /*
    |--------------------------------------------------------------------------
    | SMTP
    |--------------------------------------------------------------------------
    |
    | Here we define configuration for sending emails via SMTP.
    |
    */
    smtp: {
        driver: 'smtp',
            pool: true,
            port: process.env.SMTP_PORT || 2525,
            host: process.env.SMTP_HOST || 'smtp.mailtrap.io',
            secure: false,
            auth: {
            user: process.env.MAIL_USERNAME,
            pass: process.env.MAIL_PASSWORD
        },
        maxConnections: 5,
        maxMessages: 100,
        rateLimit: 10
    },

    /*
    |--------------------------------------------------------------------------
    | SparkPost
    |--------------------------------------------------------------------------
    |
    | Here we define configuration for spark post. Extra options can be defined
    | inside the `extra` object.
    |
    | https://developer.sparkpost.com/api/transmissions.html#header-options-attributes
    |
    | extras: {
    |   campaign_id: 'sparkpost campaign id',
    |   options: { // sparkpost options }
    | }
    |
    */
    sparkpost: {
        driver: 'sparkpost',
        // endpoint: 'https://api.eu.sparkpost.com/api/v1',
        apiKey: process.env.SPARKPOST_API_KEY,
        extras: {}
    },

    /*
    |--------------------------------------------------------------------------
    | Mailgun
    |--------------------------------------------------------------------------
    |
    | Here we define configuration for mailgun. Extra options can be defined
    | inside the `extra` object.
    |
    | https://mailgun-documentation.readthedocs.io/en/latest/api-sending.html#sending
    |
    | extras: {
    |   'o:tag': '',
    |   'o:campaign': '',,
    |   . . .
    | }
    |
    */
    mailgun: {
        driver: 'mailgun',
        domain: process.env.MAILGUN_DOMAIN,
        apiKey: process.env.MAILGUN_API_KEY,
        extras: {}
    },

    /*
    |--------------------------------------------------------------------------
    | Ethereal
    |--------------------------------------------------------------------------
    |
    | Ethereal driver to quickly test emails in your browser. A disposable
    | account is created automatically for you.
    |
    | https://ethereal.email
    |
    */
    ethereal: {
        driver: 'ethereal'
    }
}

The mail.config.js file exports an object. The following configuration variables are required:

  • connection: This represents the name of the driver to use.
  • views: This is the folder in which all your emails are stored. It defaults to /mails
  • viewsEngine: This defines what templating engine you are using for emails. For now, only handlebars and edge are supported

The last configuration required is a configuration object specific to the driver. Here's an example configuration for smtp:

    smtp: {
        driver: 'smtp',
        pool: true,
        port: process.env.SMTP_PORT || 2525,
        host: process.env.SMTP_HOST || 'smtp.mailtrap.io',
        secure: false,
        auth: {
            user: process.env.MAIL_USERNAME,
            pass: process.env.MAIL_PASSWORD
        },
        maxConnections: 5,
        maxMessages: 100,
        rateLimit: 10
    },

Usage

Here's a sample piece of code to send an email:

const Mail = require('friendly-mail')

const nameOfEmail = 'confirm-email'

const recipientName = 'John Doe'
const recipientEmail = '[email protected]'

const subject = 'Please confirm your email address.'

// Send the mail using async/await
await new Mail(nameOfEmail)
    .to(recipientEmail, recipientName)
    .subject(subject)
    .send()

Note: All publicly exposed methods on the Mail class are chainable, except the send and sendRaw which return Promises.

Common use cases

Generating emails

The package ships with a command to generate help you scaffold emails.

# Using npm
npx friendlymail generate activate-account
# Using yarn
yarn friendlymail generate activate-account

Passing data to templates

The data method can be used to set data that will be passed to the email template.

await new Mail(nameOfEmail)
    .to(recipientEmail, recipientName)
    .subject(subject)
    .data({
        name: 'John Doe',
        url: 'https://google.com'
    })
    .send()

Setting cc and bcc for a mail

await new Mail(nameOfEmail)
    .inReplyTo('[email protected]', 'Jane Doe')
    .to(recipientEmail, recipientName)
    .subject(subject)
    .cc('[email protected]', 'Eren Stales')
    .bcc('[email protected]', 'Steve Dickson')
    .send()

Sending emails to multiple recipients

The to method can recieve an array of address objects to send emails to multiple users. This also works for all other methods that set user addresses like from cc bcc inReplyTo replyTo and sender

await new Mail(nameOfEmail)
    .inReplyTo([{ address: '[email protected]', email: 'Jane Doe' }])
    .to([{ address: '[email protected]', name: 'Foo' }])
    .subject('Monthly Newsletter')
    .cc([{ address: '[email protected]', name: 'Eren Stales' }])
    .bcc([{ address: '[email protected]', name: 'Steve Dickson' }])
    .send()

Sending mails with attachments

The attach and attachData methods can be used to send attachments

// Attaching an existing file

await new Mail(nameOfEmail)
    .to(recipientEmail, recipientName)
    .subject(subject)
    .attach('/absolute/path/to/file')
    .send()

// Attaching buffer as attachment with a custom file name
const filename = 'hello.txt'
const rawData = new Buffer('hello')
await new Mail(nameOfEmail)
    .to(recipientEmail, recipientName)
    .subject(subject)
    .attachData(rawData, filename)
    .send()

// Attaching readstream as attachment with a custom file name
const filename = 'hello.txt'
const rawData = fs.createReadStream('hello.txt')

await new Mail(nameOfEmail)
    .to(recipientEmail, recipientName)
    .subject(subject)
    .attachData(rawData, filename)
    .send()

// Attaching string as attachment with a custom file name
const filename = 'hello.txt'
const rawData = 'hello'

await new Mail(nameOfEmail)
    .to(recipientEmail, recipientName)
    .subject(subject)
    .attachData(rawData, filename)
    .send()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].