Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Server-side JavaScript email automation and validation

License

Notifications You must be signed in to change notification settings

Thoughtscript/railsware-js-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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":"abcd@email.com","telegram_id":"@coolperson"},{"id":1,"name":"Larry Dude","email":"1234@email.com","telegram_id":"@dudeperson"},{"id":2,"name":"Ms. Ladyface","email":"efgh@email.com","telegram_id":"@ladyface"},{"id":3,"name":"J Nobody","email":"Nobody@email.com","telegram_id":"@Nobody"},{"id":4,"name":"Frankenstein","email":"monster@bash.com","telegram_id":"@monster"},{"id":5,"name":"Rockstar","email":"prima@donna.com","telegram_id":"@toocool"},{"id":6,"name":"beep boop","email":"imma@robot.com","telegram_id":"@robutnik"},{"id":7,"name":"Crazy Cat","email":"whiskers@chesire.com","telegram_id":"@meow"},{"id":8,"name":"The Red Devils","email":"market@garden.com","telegram_id":"@marketgarden"},{"id":9,"name":"Jar Jar Binks","email":"worst@character.ever","telegram_id":"@whatamievensaying"}]}

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

{
    "status": 200,
    "data": {
        "id": 0,
        "name": "J Everyperson",
        "email": "abcd@email.com",
        "telegram_id": "@coolperson"
    }
}

POST http://localhost:7777/api

{
    "contact": {
        "id": 15,
        "name": "New Man",
        "email": "a@new.man",
        "telegram_id": "@newman"
    }
}
{
    "status": 200,
    "data": [
        {
            "id": 0,
            "name": "J Everyperson",
            "email": "abcd@email.com",
            "telegram_id": "@coolperson"
        },
        {
            "id": 1,
            "name": "Larry Dude",
            "email": "1234@email.com",
            "telegram_id": "@dudeperson"
        },
        {
            "id": 2,
            "name": "Ms. Ladyface",
            "email": "efgh@email.com",
            "telegram_id": "@ladyface"
        },
        {
            "id": 3,
            "name": "J Nobody",
            "email": "Nobody@email.com",
            "telegram_id": "@Nobody"
        },
        {
            "id": 4,
            "name": "Frankenstein",
            "email": "monster@bash.com",
            "telegram_id": "@monster"
        },
        {
            "id": 5,
            "name": "Rockstar",
            "email": "prima@donna.com",
            "telegram_id": "@toocool"
        },
        {
            "id": 6,
            "name": "beep boop",
            "email": "imma@robot.com",
            "telegram_id": "@robutnik"
        },
        {
            "id": 7,
            "name": "Crazy Cat",
            "email": "whiskers@chesire.com",
            "telegram_id": "@meow"
        },
        {
            "id": 8,
            "name": "The Red Devils",
            "email": "market@garden.com",
            "telegram_id": "@marketgarden"
        },
        {
            "id": 9,
            "name": "Jar Jar Binks",
            "email": "worst@character.ever",
            "telegram_id": "@whatamievensaying"
        },
        null,
        null,
        null,
        null,
        null,
        {
            "id": 15,
            "name": "New Man",
            "email": "a@new.man",
            "telegram_id": "@newman"
        }
    ]
}

PUT http://localhost:7777/api

{
    "contact": {
        "id": 0,
        "name": "Changed Man",
        "email": "not@the.same",
        "telegram_id": "@differentperson"
    }
}
{
    "status": 200,
    "data": [
        {
            "id": 0,
            "name": "Changed Man",
            "email": "not@the.same",
            "telegram_id": "@differentperson"
        },
        {
            "id": 1,
            "name": "Larry Dude",
            "email": "1234@email.com",
            "telegram_id": "@dudeperson"
        },
        {
            "id": 2,
            "name": "Ms. Ladyface",
            "email": "efgh@email.com",
            "telegram_id": "@ladyface"
        },
        {
            "id": 3,
            "name": "J Nobody",
            "email": "Nobody@email.com",
            "telegram_id": "@Nobody"
        },
        {
            "id": 4,
            "name": "Frankenstein",
            "email": "monster@bash.com",
            "telegram_id": "@monster"
        },
        {
            "id": 5,
            "name": "Rockstar",
            "email": "prima@donna.com",
            "telegram_id": "@toocool"
        },
        {
            "id": 6,
            "name": "beep boop",
            "email": "imma@robot.com",
            "telegram_id": "@robutnik"
        },
        {
            "id": 7,
            "name": "Crazy Cat",
            "email": "whiskers@chesire.com",
            "telegram_id": "@meow"
        },
        {
            "id": 8,
            "name": "The Red Devils",
            "email": "market@garden.com",
            "telegram_id": "@marketgarden"
        },
        {
            "id": 9,
            "name": "Jar Jar Binks",
            "email": "worst@character.ever",
            "telegram_id": "@whatamievensaying"
        }
    ]
}

DELETE localhost:7777/api/?id=1

{
    "status": 200,
    "data": [
        {
            "id": 0,
            "name": "J Everyperson",
            "email": "abcd@email.com",
            "telegram_id": "@coolperson"
        },
        null,
        {
            "id": 2,
            "name": "Ms. Ladyface",
            "email": "efgh@email.com",
            "telegram_id": "@ladyface"
        },
        {
            "id": 3,
            "name": "J Nobody",
            "email": "Nobody@email.com",
            "telegram_id": "@Nobody"
        },
        {
            "id": 4,
            "name": "Frankenstein",
            "email": "monster@bash.com",
            "telegram_id": "@monster"
        },
        {
            "id": 5,
            "name": "Rockstar",
            "email": "prima@donna.com",
            "telegram_id": "@toocool"
        },
        {
            "id": 6,
            "name": "beep boop",
            "email": "imma@robot.com",
            "telegram_id": "@robutnik"
        },
        {
            "id": 7,
            "name": "Crazy Cat",
            "email": "whiskers@chesire.com",
            "telegram_id": "@meow"
        },
        {
            "id": 8,
            "name": "The Red Devils",
            "email": "market@garden.com",
            "telegram_id": "@marketgarden"
        },
        {
            "id": 9,
            "name": "Jar Jar Binks",
            "email": "worst@character.ever",
            "telegram_id": "@whatamievensaying"
        }
    ]
}

License

MIT Licensed - view the license.

About

Server-side JavaScript email automation and validation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published