Over a million developers have joined DZone.

Generating Emails Using Node.js

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

This post tells you how to generate emails on Node.js and open them in an email program. It uses mailto URLs to do so. The advantage of this approach is that you can manually check and edit such emails before sending them.

mailto URL syntax

"mailto:" recipients ( "?" key "=" value ("&" key "=" value)* )?

  • recipients: comma-separated email addresses (no spaces; Outlook needs semicolons instead of commas)
  • value: should be URL-encoded (e.g. space becomes %20)
  • key: subject, cc, bcc, body

Example: mailto:joe@example.com,jane@example.com?subject=hello&body=How%20are%20you%3F

Using mailto URLs on Node.js

The npm module openurl allows you to tell the operating system to open a URL. It also comes with a mailto() function that constructs well-formed mailto URLs. Example:
    require("openurl").mailto(["john@example.com", "jane@example.com"],
        { subject: "Hello!", body: "This is\na generated email!\n" });

Naturally, the same technique also works with other programming languages:



Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Published at DZone with permission of Axel Rauschmayer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}