Giter Club home page Giter Club logo

mock-smtp-old's Introduction

Mock SMTP/SMS server

The implementation supports a mock SMTP server and a mock SMS using HTTP API.

The mock smtp server listens on an SMTP port and provides the ability to receive emails. Instead of sending the emails to the necessary email id, it would send the email to the websocket so you could see the email on the browser.

The mock provides the ability to test applications that use SMTP to deliver emails.

Note: As of now we have not handled other features of SMTP/SMS. Only a happy flow is implemented.

The Mock has the following API for testing SMS.


  /sendsms: 
    get: 
      summary: ""
      description: ""
      parameters: 
        - 
          name: "mobiles"
          type: "string"
          in: "query"
          description: "To whom we should send the SMS"
          required: true
        - 
          name: "sender"
          type: "string"
          in: "query"
          description: "From whom should we send the SMS"
          required: true
        - 
          name: "message"
          type: "string"
          in: "query"
          description: "Actual message"
          required: true

In order for the mock to be efficient all additional parameters and headers are ignored.

Build and Run.

Clone the repo and run the following command to build and run.

npm install
npm start

Introduction

Type this URL http://locahost:8080/ in your browser to access the emails.

  • The emails/SMS are broadcasted to all currently open websockets. So you could miss the email/SMS if you are not connected.

  • The current connection status is shown on top of this page.

  • RELOAD button will reload the entire page. You will loose all the information currently on the screen.

  • An empty message apears as the first message (Yep i know its nasty but no time to fix this). Newer messages will apear on top of the page.

Source code

index.html - A simple html page with CDN based react running on the browser. Not the most efficient but is the simplest way to work.

app.js - The server that handles the SMTP, http & websocket.

Logs

The app prints the emails in JSON format and also updates on the number of connected clients. Please avoid using sensitive data.

Build Docker

docker build . -t mosipdev/mock-smtp:v1 --network host

Run docker

docker run -p 8025:8025 -p 8080:8080 -p 8081:8081 mosipdev/mock-smtp:v1

Configuration

Following environment variables are supported on the server

SMTP_SERVER_PORT = 8025
SERVER_PORT = 8080
WS_SERVER_PORT = 8081
SERVER_HOST = localhost //set 0.0.0.0 when running in docker

In case you use a proxy and the websocket ports are not the default ones then use following environment variables to inform the client.

WS_EX_PROTOCOL = "ws" //set this to wss if running over https
WS_EX_SERVER_PORT = 8081 // if the proxy server exposes the socker over https then set this to 443 and map the context path to the basepath
WS_EX_BASE_PATH = "" //set your base path

Test

Use the below command to send a test email

sendEmail -f [email protected] -t [email protected] -s localhost:8025 -u "Test send the mail" -m "Sending the email for test"

Use the below api to test the SMS

curl 'http://localhost:8080/sendsms?mobiles=9123456789&sender=xyz&message=this%20is%20your%20sms' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'DNT: 1' \
  -H 'Pragma: no-cache' \
  -H 'Sec-Fetch-Dest: document' \
  -H 'Sec-Fetch-Mode: navigate' \
  -H 'Sec-Fetch-Site: none' \
  -H 'Sec-Fetch-User: ?1' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  --compressed

mock-smtp-old's People

Contributors

gsasikumar avatar

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.