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

vinyl-mail

v0.1.5

Published

Send Vinyl files as email.

Downloads

12

Readme

vinyl-mail

Send Vinyl files as email.

wercker status Dependency Status

Example

The first thing to do is to create a Mail stream:

var path = require('path');
var es = require('event-stream');
var Mail = require('vinyl-mail');
var mail = new Mail({
  from: process.env.SEND_FROM,
  layout: 'email',
  template: 'email',
  viewPath: path.resolve(__dirname, 'views'),
  service: process.env.TRANSPORTER_SERVICE,
  auth: {
    user: process.env.TRANSPORTER_AUTH_USER,
    pass: process.env.TRANSPORTER_AUTH_PASS
  }
});

The from value is a default, but if omitted will need to be provided when sending each email.

The layout and template values indicate which template to use to create the email, and which layout to place that template into. The location of the templates is provided by the viewPath value.

The values in service and auth specify which email service to use, and these values are passed to nodemailer.

A typical use of the mail stream would be to provide a destination for a Gulp task. Continuing the example, we'll first create a Vinyl file that contains an email body as its contents value:

var gulp = require('gulp');
var File = require('vinyl');
gulp.task('send', function() {
  var file = new File({
    contents: new Buffer('Hello, World!')
  });

Next we augment the file with a meta property which contains the target email address, the subject of the email, and a content property which will be passed in to the template processor:

  file.meta = {
    to: '[email protected]',
    subject: 'Hello!',
    context: {
      name: 'World'
    }
  };

Now all we need to do is pipe this file to the mail stream's destination, and the file will be sent as an email:

  es.readable(function(count, callback) {
      this.emit('data', file);
    })
    .pipe(mail.dest());

Each successfully sent email emits a sent event with information about the transaction:

  es.readable(function(count, callback) {
      this.emit('data', file);
    })
    .pipe(mail.dest())
    .on('sent', function(msg) {
      console.log('Sent email:', msg);
    });