Giter Site home page Giter Site logo

flemunto5 / enmail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ackeecz/enmail

0.0 0.0 0.0 89 KB

Handles message communication with end users through various means of messages - email, sms, chat messages using uniform API.

License: MIT License

TypeScript 100.00%

enmail's Introduction

enmail

Build Status Npm License

Handles message communication with end users through various means of messages - email, sms, chat messages using uniform API.

Neither snow nor rain nor heat nor gloom of night stays these couriers from the swift completion of their appointed rounds

Install

npm i --save enmail

Supported services, their settings and examples

Quickstart

import {
    createOffice,
    getOffice,
    GmailAuthType,
    Mail,
    MailType,
    ServiceType 
} from 'enmail';

// Creates an office given the options, see below, and saves
// instance under given key. If none key given, is saved under a 'default' name.
createOffice({
    service: ServiceType.gmail,
    settings: {
        authType: GmailAuthType.login, // GmailAuthType.oauth2
        settings: {
            user: '[email protected]',
            pass: '******',
        },
    },
});
// Mail object providing universal message container used throughout
// all the offices
const mail: Mail = {
    from: '[email protected]',
    to: '[email protected]',
    type: MailType.HTML, // MailType.TEXT
    subject: 'Hello, its me',
    content: `<p>I was wondering if after all these years you'd like to meet to go over everything ...</p>`,
    // optional: mailerOptions
};
// Gets office by key. Called without parameters, gets the default instance.
getOffice()
    .send(mail)
    .then(res => /* ... */)
    .catch(e => /* ... */)
// ...

Concept

Formerly an email sender, generally a message sender. Emails - electronic mails, letters... letters are sent and delivered by a post office, thus office is the key hub for sending those messages.

Office have to be built first. Once built, offce can send a message.

Templates

import {
    // (templateString, context) Given template string
    // (https://lodash.com/docs/4.17.4#template) and variables, function compiles
    // this template and can later be used to create a message from that template
    //
    // context.locale: String (`en`, locale for i18n)
    // context.tz: String (`UTC`, timezone)
    compileLodashTemplate,
    // Same as above only templateString is a filename to that template
    compileLodashFileTemplate,
    Mail }
from 'enmail';

/*
    variables automatically exposed to be used in a template
    (aside from directly passed variables to a template and template
    compiler as a context)

    __: (key: String, ...variables) -> String
        Translation function, internally using i18n. Identity fn by default.
    dateTimeFormat: (date: Date|String, tz: String) -> String
        Date formatter using context.locale
    currencyFormat: (n: Number, currency: String) -> String
        i18n-formatted currency
    [numberFormat]: TBA
*/

const templateString = `
<!DOCTYPE html>
<html>
    <body>
        <%= __('You can recover you password here') %>
        <%= url %>?token=<%= token %>
    </body>
</html>
`
const compiled = compileLodashTemplate(templateString, { url: 'http://api', token: '__TOKEN__' })
// <!DOCTYPE html>
// <html>
//     <body>
//         You can recover you password here
//         http://api?token=__TOKEN__
//     </body>
// </html>
const mail: Mail = {
    // ...
    content: compiled(),
    // ...
};

Development

Build

npm run build

It runs tsc -p .

Testing

npm run test

Lint

npm run lint

License

This project is licensed under MIT.

enmail's People

Contributors

smolijar avatar smoliji avatar stefanprokopdev 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.