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

vercel-email

v0.0.6

Published

A simple free transactional email package built for Vercel Edge functions

Downloads

3,711

Readme

How it works

This package only works with Vercel edge functions. Vercel edge functions are serverless functions that run on the edge of the Cloudflare network. Thus, we can take advantage of Cloudflare's free outbound email service which is a result of their partnership with MailChannels. To learn more, visit the Cloudflare blog post.

Getting Started!

Install the package

npm install vercel-email

Create a new edge function

import { NextRequest, NextResponse } from 'next/server';

export const config = {
	runtime: 'edge', // this is a pre-requisite
};

Import the package

import Email from 'vercel-email';

Setup SPF

SPF is a DNS record that helps prevent email spoofing. You will need to add an SPF record to your domain to allow MailChannels to send emails on your behalf.

  1. Add a TXT record to your domain with the following values:
    • Name: @
    • Value: v=spf1 a mx include:relay.mailchannels.net ~all

Setup DKIM

This step is optional, but highly recommended. DKIM is a DNS record that helps prevent email spoofing. You may follow the steps listed in the MailChannels documentation to set up DKIM for your domain.

Usage

Basic Email

The Most basic request would look like this:

await Email.send({
	to: '[email protected]',
	from: '[email protected]',
	subject: 'Hello World',
	text: 'Hello World',
});

HTML Emails

You can also send HTML emails by adding an html parameter to the request. This can be used in conjunction with the text parameter to send a multi-part email.

await Email.send({
	to: '[email protected]',
	from: '[email protected]',
	subject: 'Hello World',
	html: '<h1>Hello World</h1>',
});

Sender and Recipient Name

You can also specify a sender and recipient name by adding a name parameter to the request. This can be used for both the to and from parameters.

await Email.send({
	to: { email: '[email protected]', name: 'John Doe' },
	from: { email: '[email protected]', name: 'Jane Doe' },
	subject: 'Hello World',
	text: 'Hello World',
});

Sending to Multiple Recipients

You may also send to multiple recipients by passing an array of eamils, or an array of objects with email and name properties.

await Email.send({
	to: ['[email protected]', '[email protected]'],
	from: '[email protected]',
	subject: 'Hello World',
	text: 'Hello World',
});

or

await Email.send({
	to: [
		{ email: '[email protected]', name: 'John Doe' },
		{ email: '[email protected]', name: 'Rose Doe' },
	],
	from: '[email protected]',
	subject: 'Hello World',
	text: 'Hello World',
});

Sending BCC and CC

You can also send BCC and CC emails by passing an array of eamils, an object with email and name properties, or an array of either, similar to the to parameter.

await Email.send({
	to: '[email protected]',
	from: '[email protected]',
	subject: 'Hello World',
	text: 'Hello World',
	cc: ['[email protected]', '[email protected]'],
	bcc: ['[email protected]'],
});

Reply To

You can also specify a reply to email address by adding a replyTo parameter to the request. Again, you can use an email string, an object with email and name properties, or an array of either.

await Email.send({
	to: '[email protected]',
	from: '[email protected]',
	replyTo: '[email protected]',
	subject: 'Hello World',
	text: 'Hello World',
});