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

@netlify/plugin-emails

v1.1.1

Published

A build plugin that creates an email handler and processes requests to send emails

Downloads

2,677

Readme

Netlify Emails Plugin

The Netlify emails build plugin is responsible for creating a serverless function to handle email requests, using the email request to populate provided email templates and sending them using the specified email API provider.

Docs

Full documentation for the Netlify Email Integration can be found here.

Supported email providers

  • Mailgun
  • SendGrid
  • Postmark

Prerequisites

You must setup an account with one of our supported email providers listed above. You will also need to ensure your account is verified by the email provider and you have provided authorisation for emails to be sent from any email address you send from.

Step 1: Enabling the Netlify Email Integration

Add it to your site via the Netlify app under Integrations - (app.netlify.com/integrations/{your-sitename}/emails).

Step 2: Configuration

When enabling the plugin via Integrations, you should add the required configuration variables to complete the configuration step.

image

Step 3: Adding Templates

Now that the setup is complete, create an email directory ./emails (default) or use a custom directory, as long as you define it in your Email Settings under ‘Template directory’.

We support both HTML and responsive MJML templates. Each email template should be stored under a folder name that represents the route of your template and the email file should be named either index.html or index.mjml. E.g. ./emails/welcome/index.html.

If there are variables that need replacing in your email template when the email is triggered, please use the handlebars.js syntax and pass the arguments in the request as shown in Step 5 below.

Sample email with parameters:

<html>
  <body>
    <h1>Welcome, {{name}}</h1>
    <p>We hope you enjoy our super simple emails!</p>
  </body>
</html>

Step 4: Previewing emails locally

Visit http://localhost:{PORT}/.netlify/functions/emails to preview your email templates.

Please note, this preview endpoint is not made available in production and is only made available locally.

Step 5: Triggering an Email

Dependent on where you would like to trigger an email being sent (on a subscribe or data request button click, when an event is triggered, etc.), add one of the following snippets to your code that is reacting to that event.

@netlify/emails:

await sendEmail({
  from: "[email protected]",
  to: "[email protected]",
  cc: "[email protected]",
  bcc: "[email protected]",
  subject: "Welcome",
  template: "welcome",
  parameters: {
    products: ["product1", "product2", "product3"],
    name: "Alexander",
  },
});

node-fetch:

 import fetch from 'node-fetch'

 await fetch(
    `${process.env.URL}/.netlify/functions/emails/welcome`,
    {
      headers: {
        "netlify-emails-secret": process.env.NETLIFY_EMAILS_SECRET,
      },
      method: "POST",
      body: JSON.stringify({
        from: "[email protected]",
        to: "[email protected]",
        cc: "[email protected]",
        bcc: "[email protected]",
        subject: "Welcome",
        parameters: {
          products: ["product1", "product2", "product3"],
          name: "Alexander",
        },
      }),
    }
  );

You can also trigger the email locally by running netlify build, then netlify dev and making the above request.