New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-emailable

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-emailable

Mongoose plugin for email with confirmation and express middleware

  • 0.0.1
  • v0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-emailable

Mongoose plugin for email address confirmation and express route: automatically sends an email with a "click to confirm address" link to a just-registered user, or to a user that changes its email address.

Clicking the link will flag the email address as "confirmed", thus allowing mails to be sent to this address. No other mails beside the "confirm your address" will be sent to an unconfirmed address.

This module internally uses nodemailer module with Amazon SES transport.

Installation

npm install mongoose-emailable

Usage

Setting up mongoose-emailable is pretty straightfoward:

  1. attach plugin to the Mongoose model of your choice (typically, a User-like model)
  2. add route to your express application

Configure mongoose model

# User model file...
mongoose = require("mongoose")
emailablePlugin = require("mongoose-emailable").plugin

UserSchema = new mongoose.Schema(
  name:
    type: String
    required: true
)

UserSchema.plugin(emailablePlugin,
  from: "Example.com <no-reply@example.com>" # Any email address you own
  confirmRoute: "https://example.com/account/email/confirm" # Query string will be automatically added
  amazonSES:
    AWSAccessKeyID: "..."
    AWSSecretKey: "..."
)

Configure express app


express = require("express")
emailableRoutes = require("mongoose-emailable").routes
UserModel = require("./path/to/your/mongoose/usermodel")

app = express()

emailableRoutes.use(app,
  model: UserModel # mandatory
)

And you're set! Users will receive an email asking for confirmation when registering.

Settings and options

Mongoose plugin

  • Settings

    • from: the sender email address, typically your address
    • confirmRoute: path to your server address route (ie. http://example.com/account/email/confirm)
    • amazonSES: an object with AWSAccessKeyID and AWSSecretKey keys
  • Options

    • subject: a string used to populate the email subject (defaults to "Confirm your account registration")
    • html: a function or string used to populate the email body (defaults: see source code)

Express route

  • Settings
    • model: any mongoose model class, most likely a User model kind.
  • Options
    • path: path to email confirmation page (default: /account/email/confirm)
    • template: template to use when rendering the email confirmation page (defaults to a simple text page)
    • reqHttpFields: any fields in express req object that you wish to automatically pass to res.locals. Simply pass an object where keys are req fields and values are res.locals fields (for example, passing { user: loggedUser } will set the value of req.user to res.locals.loggedUser.
    • middlewares: array of express middlewares you wish to pass to the route.

Mongoose plugin methods and statics

Methods

sendEmail(message, callback)

Asynchronously sends an email to any confirmed email address.

See nodemailer documentation for a full description of message object.

Statics

sendConfirmationEmail(callback)
confirmEmailAddress(callback)

TODO

  • add the ability to resend the confirmation message (generate new token ?)
  • allow option for setting custom field names, and remove dependency to name field
  • remove nodemailer dependency / allow for alternate libraries ?
  • tests
  • examples

Keywords

FAQs

Package last updated on 08 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc