township-email

    1.0.0 • Public • Published

    township-email

    A wrapper around nodemailer for township transactional emails.

    npm travis standard conduct

    About

    This module collection of helper functions for sending authentication/authorization emails.

    Example: confirming an email account

    mail.confirm({
      to: 'test@example.com',
      from: 'test@example.com',
      url: 'https://example.com/url/for/confirming/email'
    })

    Install

    npm install --save township-email

    Usage

    var townshipEmail = require('township-email')
     
    var mail = townshipEmail({
      transport: `smtps://${process.env.GMAIL_USER}%40gmail.com:${process.env.GMAIL_PASS}@smtp.gmail.com`
    })
     
    mail.confirm({
      to: 'sethvincent+emailtest@gmail.com',
      from: 'sethvincent+emailtest@gmail.com',
      url: 'https://example.com/url/for/confirming/email'
    }, function (err) {
      console.log(err)
    })

    Using nodemailer transports

    You can use any nodemailer transport you like with this library. The above example shows basic SMTP usage.

    Check out nodemailer for more information on transports

    Writing your own email HTML

    You can override any of the emails this module sends be using the emails option in the constructor.

    Each email is a function that takes an options object and returns a string.

    var townshipEmail = require('township-email')
     
    var mail = townshipEmail({
      transport: `smtps://${process.env.GMAIL_USER}%40gmail.com:${process.env.GMAIL_PASS}@smtp.gmail.com`,
      emails: {
        confirm: confirm,
        welcome: welcome
      }
    })
     
    function confirm (options) {
      return `<div>
        <p>Hello!</p>
        <p>Verify your email address by clicking this link:</p>
        <p><b><a href="${options.url}">Confirm your account</a></b></p>
        <p>Or by following this url:</p>
        <p><a href="${options.url}">${options.url}</a></p>
      </div>`
    }
     
    function welcome (options) {
      return `<div>
        <p>Welcome, and thank you for creating an account!</p>
        <p>Please reply to this email if you have any questions.</p>
      </div>`
    }

    Examples

    Contributing

    Contributions are welcome! Please read the contributing guidelines first.

    Conduct

    It's important that this project contributes to a friendly, safe, and welcoming environment for all, particularly for folks that are historically underrepresented in technology. Read this project's code of conduct

    Change log

    Read about the changes to this project in CHANGELOG.md. The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

    License

    ISC

    Install

    npm i township-email

    DownloadsWeekly Downloads

    4

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • sethvincent