1.2.0 • Published 3 years ago

service-mailing v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

MS MAILING

Service for sending mails through different providers (Mandrill etc.). 📧

It's using message broker, RabbitMQ for local DEV and GC PubSub in PROD (choice made in config).

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

It has been designed to be run inside docker containers. Dockerfile, Makefile, and docker-compose files are provided.

So you can start coding without the hassle of preparing your environment.

clone repo
make up-build

You may have to set some environment's variable, see that section.

🔩 Prerequisites

What things you need to install the software and how to install them.

🐳 Containers

  • Service
    • Port : 3000
  • Mongo
    • Port : 27017

✅ Run it

First time use:

make up-build

Next times:

make up (background mode)
or
make up-i (interactive mode)

🙌 Useful command lines

to show the sysout of the application

make logs

To run the automated UNIT tests (with lab)

make test

To run the automated FUNCTIONAL tests (with cucumber)

make e2e

To run the linter

make lint

👷 Built With

  • NodeJS
  • HapiJS
  • MongoDB
  • RabbitMQ(DEV) / GCPubSub(PROD)

Using providers as

  • Mandrill
  • Capemail

🗯 How to test the webhook locally

Push an event in your webhook mailing topic (amqp)

{
"body": {"mandrill_events": "[  {    \"event\": \"send\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [              ],      \"clicks\": [              ],      \"state\": \"sent\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  },  {    \"event\": \"deferral\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [              ],      \"clicks\": [              ],      \"state\": \"deferred\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\",      \"smtp_events\": [        {          \"destination_ip\": \"127.0.0.1\",          \"diag\": \"451 4.3.5 Temporarily unavailable, try again later.\",          \"source_ip\": \"127.0.0.1\",          \"ts\": 1365111111,          \"type\": \"deferred\",          \"size\": 0        }      ]    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  },  {    \"event\": \"hard_bounce\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"state\": \"bounced\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\",      \"bounce_description\": \"bad_mailbox\",      \"bgtools_code\": 10,      \"diag\": \"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces.\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  },  {    \"event\": \"soft_bounce\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"state\": \"soft-bounced\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\",      \"bounce_description\": \"mailbox_full\",      \"bgtools_code\": 22,      \"diag\": \"smtp;552 5.2.2 Over Quota\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  },  {    \"event\": \"open\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [        {          \"ts\": 1365111111        }      ],      \"clicks\": [        {          \"ts\": 1365111111,          \"url\": \"http:\/\/mandrill.com\"        }      ],      \"state\": \"sent\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ip\": \"127.0.0.1\",    \"location\": {      \"country_short\": \"US\",      \"country\": \"United States\",      \"region\": \"Oklahoma\",      \"city\": \"Oklahoma City\",      \"latitude\": 35.4675598145,      \"longitude\": -97.5164337158,      \"postal_code\": \"73101\",      \"timezone\": \"-05:00\"    },    \"user_agent\": \"Mozilla\/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko\/20100317 Postbox\/1.1.3\",    \"user_agent_parsed\": {      \"type\": \"Email Client\",      \"ua_family\": \"Postbox\",      \"ua_name\": \"Postbox 1.1.3\",      \"ua_version\": \"1.1.3\",      \"ua_url\": \"http:\/\/www.postbox-inc.com\/\",      \"ua_company\": \"Postbox, Inc.\",      \"ua_company_url\": \"http:\/\/www.postbox-inc.com\/\",      \"ua_icon\": \"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/postbox.png\",      \"os_family\": \"OS X\",      \"os_name\": \"OS X 10.6 Snow Leopard\",      \"os_url\": \"http:\/\/www.apple.com\/osx\/\",      \"os_company\": \"Apple Computer, Inc.\",      \"os_company_url\": \"http:\/\/www.apple.com\/\",      \"os_icon\": \"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/macosx.png\",      \"mobile\": false    },    \"ts\": 1384954004  },  {    \"event\": \"click\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [        {          \"ts\": 1365111111        }      ],      \"clicks\": [        {          \"ts\": 1365111111,          \"url\": \"http:\/\/mandrill.com\"        }      ],      \"state\": \"sent\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ip\": \"127.0.0.1\",    \"location\": {      \"country_short\": \"US\",      \"country\": \"United States\",      \"region\": \"Oklahoma\",      \"city\": \"Oklahoma City\",      \"latitude\": 35.4675598145,      \"longitude\": -97.5164337158,      \"postal_code\": \"73101\",      \"timezone\": \"-05:00\"    },    \"user_agent\": \"Mozilla\/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko\/20100317 Postbox\/1.1.3\",    \"user_agent_parsed\": {      \"type\": \"Email Client\",      \"ua_family\": \"Postbox\",      \"ua_name\": \"Postbox 1.1.3\",      \"ua_version\": \"1.1.3\",      \"ua_url\": \"http:\/\/www.postbox-inc.com\/\",      \"ua_company\": \"Postbox, Inc.\",      \"ua_company_url\": \"http:\/\/www.postbox-inc.com\/\",      \"ua_icon\": \"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/postbox.png\",      \"os_family\": \"OS X\",      \"os_name\": \"OS X 10.6 Snow Leopard\",      \"os_url\": \"http:\/\/www.apple.com\/osx\/\",      \"os_company\": \"Apple Computer, Inc.\",      \"os_company_url\": \"http:\/\/www.apple.com\/\",      \"os_icon\": \"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/macosx.png\",      \"mobile\": false    },    \"url\": \"http:\/\/mandrill.com\",    \"ts\": 1384954004  },  {    \"event\": \"spam\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [        {          \"ts\": 1365111111        }      ],      \"clicks\": [        {          \"ts\": 1365111111,          \"url\": \"http:\/\/mandrill.com\"        }      ],      \"state\": \"sent\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  },  {    \"event\": \"unsub\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [        {          \"ts\": 1365111111        }      ],      \"clicks\": [        {          \"ts\": 1365111111,          \"url\": \"http:\/\/mandrill.com\"        }      ],      \"state\": \"sent\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  },  {    \"event\": \"reject\",    \"msg\": {      \"ts\": 1365109999,      \"subject\": \"This an example webhook message\",      \"email\": \"example.webhook@mandrillapp.com\",      \"sender\": \"example.sender@mandrillapp.com\",      \"tags\": [        \"webhook-example\"      ],      \"opens\": [              ],      \"clicks\": [              ],      \"state\": \"rejected\",      \"metadata\": {        \"user_id\": 111      },      \"_id\": \"aed123e0679e44779d5e95a488abf94d\",      \"_version\": \"exampleaaaaaaaaaaaaaaa\"    },    \"_id\": \"aed123e0679e44779d5e95a488abf94d\",    \"ts\": 1384954004  }]"}
}

The mandrill_events should an array in a string. Replace _id by your mail provider id (mail.provider.id)

(Events format examples : https://gist.github.com/ramonsmits/7563502)

📚 Documentation