GithubHelp home page GithubHelp logo

thoughtscript / railsware-js-email Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 90 KB

Server-side JavaScript email automation and validation

License: MIT License

JavaScript 86.94% HTML 8.52% CSS 4.54%
mandrill mailgun sendgrid azure aws nodejs

railsware-js-email's Introduction

railsware-js-email

Railsware code repo for the JavaScript Email Validation article.

This repo demonstrates how to use NodeJS for validation, to batch, and send emails.

Check out the Railsware blog to learn several great ways to send emails using using handy client frameworks like React.js, Email.js, and Nodemailer.

Note: All credentials supplied are dummy credentials!

Features

  1. Email SDK's, frameworks, and tools:

    1. Mandrill (Mailchimp)
    2. AWS Amazon SES
    3. Microsoft Azure Sendgrid STMP Relay
    4. Mailgun
  2. Email attachment handling and batching via the above

  3. Simple SMS Gateway helper for sending texts

Email and HTML template validation techniques are described in the article! Unit tests are also provided.

Use

Sign up for these email-related accounts:

  1. Mandrill (Mailchimp)
  2. AWS Amazon SES
  3. Microsoft Azure Sendgrid STMP Relay
  4. Mailgun

Step-by-step instructions to do so are provided in the article!

Configure settings in config.js!

Start it up:

npm i
npm run start
npm run tests

By default, the http server will serve from http://localhost:7777

Shut it down:

npm run stop-linux
nom run stop-win

Email API

POST http://localhost:7777/email/ses

POST http://localhost:7777/email/azure

POST http://localhost:7777/email/mandrill

POST http://localhost:7777/email/mailgun

Each email endpoint supports basic, attachment, batch like so:

{
    "email": "basic"
}

Note: A couple batch endpoints are probably best served using a dedicated API through the automation provider - a response message is returned where this is the case.

SMS

To send an SMS text message via email you need three components:

  1. Send a basic email with text.
  2. A valid phone number.
  3. A valid carrier.

Basic Test API

Supplied to create a more realistic example. Be forewarned:

  1. These are very brittle and have no error handling!
  2. Purely in-memory NoSQL!

GET http://localhost:7777/api

{"status":200,"data":[{"id":0,"name":"J Everyperson","email":"[email protected]","telegram_id":"@coolperson"},{"id":1,"name":"Larry Dude","email":"[email protected]","telegram_id":"@dudeperson"},{"id":2,"name":"Ms. Ladyface","email":"[email protected]","telegram_id":"@ladyface"},{"id":3,"name":"J Nobody","email":"[email protected]","telegram_id":"@Nobody"},{"id":4,"name":"Frankenstein","email":"[email protected]","telegram_id":"@monster"},{"id":5,"name":"Rockstar","email":"[email protected]","telegram_id":"@toocool"},{"id":6,"name":"beep boop","email":"[email protected]","telegram_id":"@robutnik"},{"id":7,"name":"Crazy Cat","email":"[email protected]","telegram_id":"@meow"},{"id":8,"name":"The Red Devils","email":"[email protected]","telegram_id":"@marketgarden"},{"id":9,"name":"Jar Jar Binks","email":"[email protected]","telegram_id":"@whatamievensaying"}]}

GET http://localhost:7777/api/one?id=0

{
    "status": 200,
    "data": {
        "id": 0,
        "name": "J Everyperson",
        "email": "[email protected]",
        "telegram_id": "@coolperson"
    }
}

POST http://localhost:7777/api

{
    "contact": {
        "id": 15,
        "name": "New Man",
        "email": "[email protected]",
        "telegram_id": "@newman"
    }
}
{
    "status": 200,
    "data": [
        {
            "id": 0,
            "name": "J Everyperson",
            "email": "[email protected]",
            "telegram_id": "@coolperson"
        },
        {
            "id": 1,
            "name": "Larry Dude",
            "email": "[email protected]",
            "telegram_id": "@dudeperson"
        },
        {
            "id": 2,
            "name": "Ms. Ladyface",
            "email": "[email protected]",
            "telegram_id": "@ladyface"
        },
        {
            "id": 3,
            "name": "J Nobody",
            "email": "[email protected]",
            "telegram_id": "@Nobody"
        },
        {
            "id": 4,
            "name": "Frankenstein",
            "email": "[email protected]",
            "telegram_id": "@monster"
        },
        {
            "id": 5,
            "name": "Rockstar",
            "email": "[email protected]",
            "telegram_id": "@toocool"
        },
        {
            "id": 6,
            "name": "beep boop",
            "email": "[email protected]",
            "telegram_id": "@robutnik"
        },
        {
            "id": 7,
            "name": "Crazy Cat",
            "email": "[email protected]",
            "telegram_id": "@meow"
        },
        {
            "id": 8,
            "name": "The Red Devils",
            "email": "[email protected]",
            "telegram_id": "@marketgarden"
        },
        {
            "id": 9,
            "name": "Jar Jar Binks",
            "email": "[email protected]",
            "telegram_id": "@whatamievensaying"
        },
        null,
        null,
        null,
        null,
        null,
        {
            "id": 15,
            "name": "New Man",
            "email": "[email protected]",
            "telegram_id": "@newman"
        }
    ]
}

PUT http://localhost:7777/api

{
    "contact": {
        "id": 0,
        "name": "Changed Man",
        "email": "[email protected]",
        "telegram_id": "@differentperson"
    }
}
{
    "status": 200,
    "data": [
        {
            "id": 0,
            "name": "Changed Man",
            "email": "[email protected]",
            "telegram_id": "@differentperson"
        },
        {
            "id": 1,
            "name": "Larry Dude",
            "email": "[email protected]",
            "telegram_id": "@dudeperson"
        },
        {
            "id": 2,
            "name": "Ms. Ladyface",
            "email": "[email protected]",
            "telegram_id": "@ladyface"
        },
        {
            "id": 3,
            "name": "J Nobody",
            "email": "[email protected]",
            "telegram_id": "@Nobody"
        },
        {
            "id": 4,
            "name": "Frankenstein",
            "email": "[email protected]",
            "telegram_id": "@monster"
        },
        {
            "id": 5,
            "name": "Rockstar",
            "email": "[email protected]",
            "telegram_id": "@toocool"
        },
        {
            "id": 6,
            "name": "beep boop",
            "email": "[email protected]",
            "telegram_id": "@robutnik"
        },
        {
            "id": 7,
            "name": "Crazy Cat",
            "email": "[email protected]",
            "telegram_id": "@meow"
        },
        {
            "id": 8,
            "name": "The Red Devils",
            "email": "[email protected]",
            "telegram_id": "@marketgarden"
        },
        {
            "id": 9,
            "name": "Jar Jar Binks",
            "email": "[email protected]",
            "telegram_id": "@whatamievensaying"
        }
    ]
}

DELETE localhost:7777/api/?id=1

{
    "status": 200,
    "data": [
        {
            "id": 0,
            "name": "J Everyperson",
            "email": "[email protected]",
            "telegram_id": "@coolperson"
        },
        null,
        {
            "id": 2,
            "name": "Ms. Ladyface",
            "email": "[email protected]",
            "telegram_id": "@ladyface"
        },
        {
            "id": 3,
            "name": "J Nobody",
            "email": "[email protected]",
            "telegram_id": "@Nobody"
        },
        {
            "id": 4,
            "name": "Frankenstein",
            "email": "[email protected]",
            "telegram_id": "@monster"
        },
        {
            "id": 5,
            "name": "Rockstar",
            "email": "[email protected]",
            "telegram_id": "@toocool"
        },
        {
            "id": 6,
            "name": "beep boop",
            "email": "[email protected]",
            "telegram_id": "@robutnik"
        },
        {
            "id": 7,
            "name": "Crazy Cat",
            "email": "[email protected]",
            "telegram_id": "@meow"
        },
        {
            "id": 8,
            "name": "The Red Devils",
            "email": "[email protected]",
            "telegram_id": "@marketgarden"
        },
        {
            "id": 9,
            "name": "Jar Jar Binks",
            "email": "[email protected]",
            "telegram_id": "@whatamievensaying"
        }
    ]
}

License

MIT Licensed - view the license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.