NodeJS – Send email by Nodemailer

In the tutorial, we guide how to send email from Node.js applications by Nodemailer module.

Nodemailer Module

Nodemailer is licensed under MIT license. It provides an easy way to send email.

To download and install it, we use below commandline:

Nodemailer Send Mail

Results:

-> Logs on console:

Nodejs - sending mail with Nodemailer

Nodemailer Attachment File

Attachments option in the message object that contains an array of attachment objects. Attachment object’s properties:

  • filename: the name of the attached file
  • content: String, Buffer or a Stream contents
  • path: path to the file
  • href: URL to the file
  • contentType: optional content type for the attachment
  • contentDisposition: optional content disposition type for the attachment, defaults to ‘attachment’
  • cid: optional content id for using inline images in HTML message source
  • encoding: Example values: ‘base64’, ‘hex’, ‘binary’ etc
  • headers: custom headers for the attachment node
  • raw: optional value that overrides entire contents of current mime node including mime headers

Example case:

Practice:

-> Result:

nodejs-nodemail-attachments

By grokonez | April 22, 2018.



Related Posts


1 thought on “NodeJS – Send email by Nodemailer”

Got Something To Say:

Your email address will not be published. Required fields are marked *

*