Skip to content

webhook allowing to pull mails and send requests to an callback url

License

Notifications You must be signed in to change notification settings

jo-hoe/go-mail-webhook-service

Repository files navigation

Go Mail Webhook Service

Test Status Lint Status Go Report Card Coverage Status

Webhook allows to pull mails and send requests to a callback URL.

Prerequisites

Mail Client

Currently, the only supported mail client is GMail. You will need the client credentials file, which you should set to the name client_secret.json and the request.token file. An example of creating it is described here. Once created, use the configuration file to set the directory where both files are stored.

Optional Components

Run the project using make. Make is typically installed by default on Linux and Mac.

If you do not have it and run on Windows, you can directly install it from gnuwin32 or via winget

winget install GnuWin32.Make

If you want to run the project without Docker, you can install Golang

Configuration Example

Create a file with the name config.yaml in directory config. An example of the configuration file is described below.

- mailClientConfig: 
    mail: "example@gmail.com" # mail address to be checked
    credentialsPath: "/path/to/client_secrets/file/" # location of the credentials files for the mail client, can also be a location relative to the current directory
  runOnce: false # if set to true, the service will run once and exit, default is false
  intervalBetweenExecutions: 0s # interval between executions of the service, default is 0 seconds
  subjectSelectorRegex: ".*" # regex to match the subject of the mail
  bodySelectorRegexList: # regex to match the body of the mail, if no body is needed do not set this
  - name: "test" # name json attribute in the callback 
    regex: "[a-z]{0,6}" # regex which matches the body, is set as value of the json attribute
  - name: "test2"
    regex: ".*"
  callback:
    url: "https://example.com/callback" # callback url
    method: "POST" # method of the callback, has to be provided as uppercase string
    timeout: 24s # timeout for the callback, default is 24 seconds
    retries: 0 # number of retries for the callback, default is 0

How to use

After you have fulfilled the prerequisites, you can start the service.

Start

Either via docker compose

docker compose up

or use make

make

Linting

Project used golangci-lint for linting.

Installation

See https://golangci-lint.run/usage/install/

Execution

Run the linting locally by executing

golangci-lint run ./...

in the working directory