npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imicros-mails

v0.0.4

Published

Moleculer service for sending mails via smtp

Downloads

3

Readme

imicros-mails

Build Status Coverage Status Development Status

Moleculer service for sending mails via smtp

Requires additional running services: imicros-minio and imicros-keys

Installation

$ npm install imicros-mails --save

Usage

Setup service

"use strict";

const { Mails } = require("imicros-mails");
const { AclMixin } = require("imicros-acl");
const { MinioMixin, SecretsMixin } = require("imicros-minio");

module.exports = {
    name: "mails",
    mixins: [Mails, MinioMixin({ service: "minio" }), AclMixin, SecretsMixin({ service: "keys" })],
                           
	/**
	 * Service settings
	 */
    settings: {},
	
	/**
	 * Service dependencies
	 */
    dependencies: ["minio","keys"],

    /**
	 * Service created lifecycle event handler
	 */
    created() {},

	/**
	 * Service started lifecycle event handler
	 */
    started() {},

	/**
	 * Service stopped lifecycle event handler
	 */
    stopped() {}
};

Usage service

  • smtp { account, settings } => account
  • verify { account } => { test, err}
  • send { account, message } => result

Verify connection

let params = {
    account: {
        smtp: {                       // connection settings: refer to nodemailer
            host: "mail.myhost.com",
            port: "465",
            secure: true,
            requireTLS: true
        },
        auth: {
            user: "[email protected]",
            pass: {
                _encrypt: {
                    value: account.pass
                }
            }
        }
    }
};
await broker.call("mails.verify", params, opts).then(res => {
    console.log(res.account); // "test"
});

Save connection

let params = {
    account: "test",
    settings: {
        // connection settings: refer to nodemailer documentation
        smtp: {
            host: "mail.myhost.com",
            port: "465",
            secure: true,
            requireTLS: true
        },
        auth: {
            user: "[email protected]",
            pass: {
                _encrypt: {
                    value: account.pass
                }
            }
        }
    }
};
await broker.call("mails.smtp", params, opts).then(res => {
    console.log(res.account); // "test"
});

Send mail

const fs = require("fs");
let params = {
    account: "test",
    // message object: refer to nodemailer documentation
    message: {
        // Comma separated list of recipients
        to: "Max Mustermann <[email protected]>",

        // Subject of the message
        subject: "Nodemailer is unicode friendly ✔",

        // plaintext body
        text: "Hello to myself!",

        // HTML body
        html:
            "<p><b>Hello</b> to myself <img src=\"cid:[email protected]\"/></p>" +
            "<p>Here's the imicros logo for you as an embedded attachment:<br/><img src=\"cid:[email protected]\"/></p>",

        // An array of attachments
        attachments: [
            // String attachment
            {
                filename: "notes.txt",
                content: "Some notes about this e-mail",
                contentType: "text/plain" // optional, would be detected from the filename
            },

            // Binary Buffer attachment
            {
                filename: "image.png",
                content: Buffer.from(
                    "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/" +
                        "//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U" +
                        "g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC",
                    "base64"
                ),

                cid: "[email protected]" // should be as unique as possible
            },

            // File Stream attachment
            {
                filename: "logo imicros ✔.png",
                content: fs.createReadStream("assets/imicros.png"),
                cid: "[email protected]" // should be as unique as possible
            }
        ]                    
    }
};
let res = await broker.call("mails.send", params, opts);
console.log(res);
/*
{ accepted: [ '[email protected]' ],
  rejected: [],
  envelopeTime: 60,
  messageTime: 355,
  messageSize: 17051,
  response:
   '250 Accepted [STATUS=new MSGID=XSGpENwpOWUvmNbGXSGpEdEoY2VsWvv3AAAAAS1yzYsg0f4g5G02QvJAu0A]',
  envelope:
   { from: '[email protected]',
     to: [ '[email protected]' ] },
  messageId: '<[email protected]>' }
*/

ToDo's