node-red-node-email-variable 1.0.6
Node-RED nodes to send and receive simple emails.
node-red-node-email-variable
Node-RED nodes to send and receive simple emails.
Pre-requisite
You will need valid email credentials for your email server. For GMail this may mean getting an application password if you have two-factor authentication enabled.
Note : Version 1.x of this node requires Node.js v8 or newer.
Install
You can install by using the Menu - Manage Palette
option, or running the following command in your
Node-RED user directory - typically ~/.node-red
cd ~/.node-red
npm i node-red-node-email-variable
GMail users
If you are accessing GMail you may need to either enable an application password, or enable less secure access via your Google account settings.
Usage
Nodes to send and receive simple emails.
Input node
Fetches emails from an IMAP or POP3 server and forwards them onwards as messages if not already seen.
The subject is loaded into msg.topic
and msg.payload
is the plain text body.
If there is text/html then that is returned in msg.html
. msg.from
and
msg.date
are also set if you need them.
Additionally msg.header
contains the complete header object including
to, cc and other potentially useful properties.
Variables credentials
You can also set
msg.host
,msg.userid
,msg.password
in the payload, which will override server, login and password default values. For example, if the data is stored in a database or elsewhere. Optionally, you can setmsg.port
in the payload, which will override port default value. {.is-info}
Output node
Sends the msg.payload
as an email, with a subject of msg.topic
.
The default message recipient can be configured in the node, if it is left
blank it should be set using the msg.to
property of the incoming message.
The email from can be set using msg.from
but not all mail services allow
this unless msg.from
is also a valid userid or email address associated with
the password. Note: if userid
or msg.from does not contain a valid email
address (userxx@some_domain.com), you may see (No Sender) in the email.
The payload can be html format. You can also specify msg.plaintext
if the main payload is html.
If the payload is a binary buffer then it will be converted to an attachment.
The filename should be set using msg.filename
. Optionally
msg.description
can be added for the body text.
Alternatively you may provide msg.attachments
which should contain an array of one or
more attachments in nodemailer format.
Uses the nodemailer npm module.
More advanced fields
Routing options
- sender - An email address that will appear on the Sender: field (always prefer from if you’re not sure which one to use)
- replyTo - An email address that will appear on the Reply-To: field
- inReplyTo - The Message-ID this message is replying to
- references - Message-ID list (space separated string)
Content options
- watchHtml - Apple Watch specific HTML version of the message. Latest watches have no problems rendering text/html content so watchHtml is most probably never seen by the recipient
- amp - AMP4EMAIL specific HTML version of the message, same usage as with text and html. See AMP example below for usage
AMP example
let message = {
from: 'Nodemailer <[email protected]>',
to: 'Nodemailer <[email protected]>',
subject: 'AMP4EMAIL message',
text: 'For clients with plaintext support only',
html: '<p>For clients that do not support AMP4EMAIL or amp content is not valid</p>',
amp: `<!doctype html>
<html ⚡4email>
<head>
<meta charset="utf-8">
<style amp4email-boilerplate>body{visibility:hidden}</style>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
</head>
<body>
<p>Image: <amp-img src="https://cldup.com/P0b1bUmEet.png" width="16" height="16"/></p>
<p>GIF (requires "amp-anim" script in header):<br/>
<amp-anim src="https://cldup.com/D72zpdwI-i.gif" width="500" height="350"/></p>
</body>
</html>`
}
Header options
- headers - An object or array of additional header fields (e.g. {“X-Key-Name”: “key value”} or [{key: “X-Key-Name”, value: “val1”}, {key: “X-Key-Name”, value: “val2”}]). Read more about custom headers here
- messageId - optional Message-Id value, random value will be generated if not set
- date - optional Date value, current UTC string will be used if not set
- list - helper for setting List-* headers (see more here)
Other options
- icalEvent - iCalendar event to use as an alternative. See details here
- encoding - identifies encoding for text/html strings (defaults to ‘utf-8’, other values are ‘hex’ and ‘base64’)
- textEncoding - force content-transfer-encoding for text values (either quoted-printable or base64). By default the best option is detected (for lots of ascii use quoted-printable, otherwise base64)
Support for different languages
Available module languages are implemented in the library i18n
- en English
- de German
- ja Japanese
- ru Russian
- ua Ukrainian