Skip to content

Sendgrid Rest mock server that runs on port 3000 and allows searching for intended email recipient.

License

Notifications You must be signed in to change notification settings

WATTx/sendgrid-mock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sendgrid-Mock

This docker allows mocking the real Sendgrid Rest Server.

Being specially useful when testing it speeds up mail automation, eliminating the need to poll for services like real email servers (gmail, etc.) or Mailinator.

TL;DR

docker run -d --name mailserver -p 3000:3000 tfsoares/sendgrid-mock

What to change on Sendgrid

This will store the sent email on memory, allowing the recipient to be searched.

The endpoint used is: POST http://<docker_gateway>/api/mail.send.json in place of the real service endpoint POST https://api.sendgrid.com/api/mail.send.json.

The configurations would be:

Node.js
require('sendgrid')(sendgrid_username, sendgrid_password, {
    "protocol":"http",
    "host": "<docker_gateway>",
    "port":3000 
});
Java
new SendGrid("SENDGRID USERNAME", "SENDGRID_PASSWORD")
    .setUrl("http://<docker_gateway>:3000");

Read Messages

This endpoint will allow knowing if an email sending has been requested.

Endpoint

GET http://<docker_gateway>:3000/api/mail.read.json/<email_to_search>

Response

{ "total": <how_may_mails>, "results": [<mails>] }

Clear messages

This will clear all cached emails. This can not be reversed.

Endpoint

GET http://<docker_gateway>:3000/api/mail.clear.json

Response

{ "message": "success", "errors": [] }

Run

To run this docker you will need to have Docker and installed. You can also just run the bash script build_and_run.sh.

Thanks

About

Sendgrid Rest mock server that runs on port 3000 and allows searching for intended email recipient.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 66.5%
  • HTML 26.6%
  • Shell 3.9%
  • Dockerfile 3.0%