Giter VIP home page Giter VIP logo

node-mailman's Introduction

Package: alinex-mailman

Build Status Coverage Status Dependency Status

Email based interface to control processes. This enables an user to send commands through email. The incoming mails will be scanned automatically, checked and if valid the command will be processed sending back a reply with the command's log.

  • imap mail support
  • filter emails to access
  • authentication possible
  • remote control
  • complete logging

It is one of the modules of the Alinex Namespace following the code standards defined in the General Docs.

Install

NPM Downloads

Install the package globally using npm on a central server. From there all your machines may be checked:

sudo npm install -g alinex-mailman --production

After global installation you may directly call mailman from anywhere.

mailman --help

Because this application works agentless, you don't have to do something special on your clients but often some simple changes can make the reports more powerful. If so you will get a hint in the report.

Always have a look at the latest changes.

Usage

After the mailman is configured you can start it once using:

> mailman

This will run the manager one time, check the emails run all required commands, send the replies like configured and finish.

The service may run with multiple verbose levels:

  • '-v' - to only show each run and numer of calls per job
  • '-vv' - to display if email is send
  • '-vvv' - to display what is called (with variables)

If the service is running you may also request the online help by sending subject: help me to it's email address.

Run as a service

To run the controller continuously use the daemon option and start it in the background.

> mailman -d -C > /var/log/mailman.log 2>&1 &

This will run the process continuously in daemon mode checking every few minutes for mails to be processed.

For production use you may start it using pm2. pm2 start mailman -- --daemon

Try mode

Mostly for testing you may use the try mode:

> mailman -t

That will run mailman normally but won't change the email so it can be used over and over again. Alternatively you may mark the email as 'unread' to reenable it.

Configuration

The base configuration for /mailman looks like:

# Configuration for mailman
# =================================================================

# IMAP Server to check for mails
mailcheck:
  # Username for login
  user: [email protected]
  # Password for login
  password: mypass
  # Host or IP address to connect to
  host: mail.mycompany.de
  # Connection port
  port: 143
  # Secure login, set to true to login through TLS
  tls: false
  # TLS Upgrade decides when to upgrade to a secure session:
  # one of 'always', 'required', 'never'
  autotls: never
  # Connection timeout in milliseconds to wait to establish connection"
  connTimeout: 10s
  # Authentication timeout in milliseconds to wait to authenticate user"
  authTimeout: 5s

# Check interval to recheck for new emails in daemon mode
interval: 5m

And then the commands under /mailman/comand/ will look like:

# Commands
# -------------------------------------------------------------------
command:
  # Object of possible commands to use
  date:
    # Title and description used for the mail response
    title: "Get the Date"
    description: "Get the date from the server."
    # Filter rules which define the emails to react on
    filter:
      # case-insensitive part of the subject
      subject: 'what time is it'
      # address or list of addresses, also as case-insensitive parts
      from: '@mycompany.de'
    # Variables to support from body
    variables:      
      format:
        type: 'string'
    # Command to execute
    exec:
      # executional on command line
      cmd: 'date'
      # list of arguments
      args: []
    # response mail settings
    email:
      # use the template
      base: default
    # send an email only on error
    emailOnlyOnError: true

Within the args you may use specific parameters given in mail body (but use them all in lowercase). Also the following general variables are present:

  • _mail - the mail object
    • header - some mail header fields like from, cc, bcc, subject, messageId
    • body - text and html body if available
  • _json - complete parameters

So you may use the email address of the sender as _mail.header.from to give it to your command.

The email templates are stored under /email will look like:

# Email Templates
# -------------------------------------------------------------------
default:
  # specify how to connect to the server
  transport: smtp://alexander.schilling%40mycompany.de:<<<env://PW_ALEX_COM>>>@mail.mycompany.de
  # sender address
  from: [email protected]
  replyTo: [email protected]

  # content
  locale: de
  subject: >
    Re: {{conf.title}}
  body: |+
  {{conf.title}}
  ==========================================================================

  {{conf.description}}

  Started on {{dateFormat date "LL"}} from {{dateFormat process.start "LTS"}} to {{dateFormat process.end "LTS"}}

  PID {{process.host}}#{{process.pid}}

  {{#if result.code}}
  ::: alert
  **{{{result.error}}}** (Code {{result.code}})
  :::
  {{/if}}

  {{#if result.stdout}}
  Output of command was:

  `` ` text
  {{{result.stdout}}}
  `` `
  {{/if}}

  {{#if result.stderr}}
  Error output from command was:

  `` ` text
  {{{result.stderr}}}
  `` `
  {{/if}}

License

(C) Copyright 2016 Alexander Schilling

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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.