Giter Club home page Giter Club logo

mailtojson's Introduction

MailToJson

Quick script to parse incoming mail and do a post with the content as JSON data.

How to use

The work flow is quite simple. The script reads the mail mime message from STDIN, parses the data and makes a POST call with RAW JSON to the url (passed as command line argument).

Example usage (command line):

cat mail.eml | python mailtojson.py -u https://dev.url/autoreply/handle.php

Example usage (postfix aliases):

mailtojson_autoreply: "|/nethosting/mailtojson/mailtojson.py -u https://dev.url/autoreply/handle.php"

JSON Format

json:
  headers:
    header_key1: value
    header_key2: value
  subject: "The email subject as utf-8 string"
  datetime: "2015-03-17 17:48:06"
  encoding: "utf-8"
  from:
    - { name: "Sender Name", email: "[email protected]" }
  to:
    - { name: "Recipient Name", email: "[email protected]" }
    - { name: "Recipient Name 2", email: "[email protected]" }
  cc:
    - { name: "Recipient Name", email: "[email protected]" }
    - { name: "Recipient Name 2", email: "[email protected]" }
  parts:
    - { content_type: "text/plain", content: "body of this part", "headers": { "header_key1": value, "header_key2": value } }
    - { content_type: "text/html", content: "body of this part", "headers": { "header_key1": value, "header_key2": value } }
  attachments:
    - { filename": "invoice.pdf", content_type: "application/pdf", content: "base64 of binary data" }
    - { filename": "invoice2.pdf", content_type: "application/pdf", content: "base64 of binary data" }

Handling JSON data in PHP

Here is a quick example of how to parse the JSON data posted by the mail to json script:

<?php

$json_str  = file_get_contents("php://input");
$json_data = json_decode($json_str, true);

var_dump($json_data);
?>

License

This code is released under MIT license by Newsman App - Smart Email Service Provider.

mailtojson's People

Contributors

dazoot avatar elliotdavies avatar grintor avatar

Watchers

 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.