Movatterモバイル変換


[0]ホーム

URL:


Nodemailer > Nodemailer

Nodemailer

Nodemailer is a module for Node.js applications that allows easy email sending. The project started in 2010 when there were few reliable options for sending email messages, and today, it is the default solution for most Node.js users.

npm install nodemailer

Check outEmailEngine – a self-hosted email gateway that allows you to make REST requests to IMAP and SMTP servers. EmailEngine also sends webhooks whenever something changes on the registered accounts.

Using the email accounts registered with EmailEngine, you can receive andsend emails. It supports OAuth2, delayed sends, opens and clicks tracking, bounce detection, and more, all without needing an external MTA service.

Nodemailer features

  • A single module withzero dependencies – easy to audit the code with no hidden complexities
  • Emphasis onsecurity – avoidRCE vulnerabilities
  • Unicode support to use any characters, including emoji 💪
  • Windows support – install withnpm on Windows without any compiled dependencies. Perfect for use with Azure or on your local Windows machine
  • SendHTML content withplain text alternatives
  • AttachAttachments to emails
  • EmbedImages in HTML emails so your design doesn’t get blocked
  • Secure email delivery withTLS/STARTTLS
  • Varioustransport methods beyond the defaultSMTP support
  • Sign emails withDKIM
  • CustomPlugin support for advanced message manipulation
  • SupportsOAuth2 authentication
  • Proxies for SMTP connections
  • ES6 codebase – fewer chances of memory leaks from hoistedvar’s
  • Autogenerated test email accounts fromEthereal.email

Requirements

  • Node.js v6.0.0 or newer. That’s all you need.

If you’re running Node.js version 6 or later, you can use Nodemailer. There are no specific platform or resource requirements. All Nodemailer methods support both callbacks and Promises (if no callback is provided). If you want to useasync..await, you’ll need Node.js v8.0.0 or newer.

TL;DR

To send an email, follow these steps:

  1. Create a Nodemailer transporter using eitherSMTP oranother transport method
  2. Set up yourmessage options (who sends what to whom)
  3. Deliver the message using thesendMail() method of your transporter

Example

Below is an example to send an email with both plain text and HTML content usingEthereal Email.

constnodemailer=require("nodemailer");consttransporter=nodemailer.createTransport({host:"smtp.ethereal.email",port:587,secure:false,// true for port 465, false for other portsauth: {user:"maddison53@ethereal.email",pass:"jn7jnAPss4f63QBp6D",  },});// async..await is not allowed in global scope, must use a wrapperasyncfunctionmain() {// send mail with defined transport objectconstinfo=awaittransporter.sendMail({from:'"Maddison Foo Koch 👻" <maddison53@ethereal.email>',// sender addressto:"bar@example.com, baz@example.com",// list of receiverssubject:"Hello ✔",// Subject linetext:"Hello world?",// plain text bodyhtml:"<b>Hello world?</b>",// html body  });console.log("Message sent: %s",info.messageId);// Message sent: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>}main().catch(console.error);

Examples

  • Nodemailer AMQP example: Learn how to use RabbitMQ with Nodemailer for email message management.Source.

Output from theexample script viewed through theEthereal mail catching service:

Source

Find the Nodemailer source code onGitHub.


Nodemailer was created byAndris Reinman, and the Nodemailer logo was designed bySven Kristjansen.


[8]ページ先頭

©2009-2025 Movatter.jp