Troubleshooting
Why Node-RED MQTT payloads never set the AWS SNS email subject
Short answer
An MQTT payload property never sets the AWS SNS email subject: an AWS IoT rule action forwards your payload as message data, and only an SNS Publish call with its Subject parameter filled controls the subject line. Publish to SNS from Node-RED or from a server-side function the rule invokes, keep MessageStructure unset for single-audience alarms, and expect JSON mode to reject a payload keyed by subject and message.
On this page
- Why does the email arrive with the subject AWS Notification Message?
- Why does adding a subject field to the MQTT payload change nothing?
- Why does the email stop arriving after I switch the message to JSON?
- How do you get a custom subject without breaking delivery?
- Which hop should you check before changing anything?
- What limits apply once the publish path works?
- How do you verify the new subject without duplicate emails?
- Questions asked
The subject line of an AWS SNS email is set by exactly one thing: the Subject parameter of the SNS Publish operation. An MQTT payload forwarded by an AWS IoT rule never reaches that parameter, so your subject property travels as ordinary message text and the email keeps the default subject, AWS Notification Message. The fix is a publishing path that exposes the parameter: call Publish from the Node-RED host, or invoke a server-side publisher from the IoT rule and map the event onto its separate subject and message inputs. Keep the direct rule action only where the default subject is acceptable.
Why does the email arrive with the subject AWS Notification Message? #
SNS falls back to the default subject AWS Notification Message whenever a Publish call leaves its Subject parameter empty, and the AWS IoT rule action has no input that maps payload data onto that parameter — it forwards your MQTT payload as message data and nothing else.
The Publish operation documented in the SNS API reference takes three inputs that matter here: Message, an optional Subject, and an optional MessageStructure. The Subject input exists to become the subject line when delivery goes to email endpoints; left empty, it triggers the default subject. These are publish-level parameters, and nothing downstream of the publish call can add one.
The SNS rule action in AWS IoT is documented to send an MQTT message from AWS IoT as an SNS push notification. It carries message content only: no subject input, no field-to-parameter mapping. In the reported setup, Node-RED publishes a warning over MQTT, the rule forwards the payload, and SNS emails it — each of those emails is a Publish call with an empty Subject, so each one shows the default subject. No payload change can alter that.
Why does adding a subject field to the MQTT payload change nothing? #
MQTT transports the payload as opaque bytes, so a subject key is application data, not an email header; in the rule's raw message mode the entire payload becomes the SNS message body, and the subject text travels inside it like any other field.
Email headers are applied by SNS at delivery time, from the publish call's inputs. Your payload is delivered content: in raw mode the whole object is the body, so the string you wrote for the subject appears inside the email text, one field among the rest. Renaming the key, changing its case, or nesting it deeper changes nothing, because no component on the path reads payload keys as email semantics.
Treat the delivered email from the raw test as your baseline: default subject, body equal to the published payload. That baseline is already a complete working delivery path, so judge every later change against it rather than against a suspected transport fault.
Why does the email stop arriving after I switch the message to JSON? #
Switching to JSON mode sets the MessageStructure parameter to json, and SNS then reads the message as its documented protocol-keyed structure rather than as free text; a payload keyed by subject and message lacks the required fallback entry, so the publish fails before any email is generated.
The documented requirement is strict: with MessageStructure set to json, Message must be a JSON object whose entries name delivery protocols, with one fallback entry every protocol can use; per-protocol entries then override that fallback for their own transport. Your alarm object, keyed by subject and message, has no protocol entries at all, so the structure check fails and the publish is rejected. The email is not lost on the way to the mailbox — it is never generated.
The reported symptom, silence after the JSON switch, matches a rejected publish exactly. Check the rule's error diagnostics instead of the mailbox: a publish rejection shows there, while everything after a successful publish looks normal even when no email exists yet.
Note the ceiling of that structure even when it is correct: its entries carry per-protocol message text only, never a subject value, so a perfectly formed object would still leave the subject at the default. For a single email audience, leave MessageStructure unset and publish plain text; the JSON structure pays for itself only when one publish must carry different text per transport.
How do you get a custom subject without breaking delivery? #
Publish to SNS only from a step that exposes the Subject parameter — from the Node-RED host itself when it holds secure AWS credentials, or from a server-side function the rule invokes when MQTT must stay the device transport; keep the direct action only if the default subject is acceptable.
| Route | Path | Where the subject is set | Choose it when |
|---|---|---|---|
| Keep the rule action unchanged | Node-RED → MQTT → AWS IoT → SNS action → email | nowhere; the default subject stands | the default subject is acceptable |
| Publish from the Node-RED host | Node-RED → SNS Publish → email | the Subject input beside the Message input | the host runs an AWS identity scoped to publishing, and your SNS integration exposes a subject input |
| Server-side publisher behind the rule | Node-RED → MQTT → AWS IoT → publisher function → SNS Publish → email | the function maps event fields onto Subject and Message | MQTT stays the device-facing transport and publish rights stay off the Node-RED host |
For the alarm flow as reported, add the server-side publisher: the rule already fires, so the only change is its routing target, and SNS publish permissions never reach the Node-RED host. Publish directly from Node-RED when that host already runs a tightly scoped AWS identity and your installed SNS integration exposes a subject input; it is one hop shorter.
Keep AWS credentials out of MQTT payloads and exported flows: the publisher function should carry its publish-only permission to the one topic in its own execution identity, never as message data or a pasted flow snippet.
Which hop should you check before changing anything? #
A working raw-mode email proves every hop after the MQTT publish — rule match, SNS action, subscription, mailbox — so a subject-only fault almost never lives in cabling, broker ports or subscriptions; confirm the payload reaches AWS IoT unchanged and then change code, not infrastructure.
- Sensor into Node-RED: the measured value changes and crosses the configured temperature limit, so the alarm event actually fires.
- Node-RED into AWS IoT: the published payload arrives byte-for-byte as configured. If nothing arrives at all, that is a connection fault, not a subject fault — Fix a PLC MQTT client that never reaches your broker covers it. If the payload arrives with stray or shifted characters, fix the encoding first, as in Fixing extra characters in a PLC MQTT JSON payload.
- Rule to action: the rule matches, the action fires, and the error diagnostics stay clean.
- Action to SNS: in raw mode the publish is accepted; in JSON mode this is the hop where the rejection happens.
- SNS to mailbox: read the delivered email's subject and body from the message headers, not from the preview pane.
Read broker address, port and topic from the deployed configuration and keep them identical across the raw and JSON tests, so the comparison isolates message handling and nothing else.
What limits apply once the publish path works? #
The default Publish size ceiling is 256 KiB per message, so a normal alarm payload is never the constraint; what decides the email is message structure and, for the subject line, the length and character constraints documented with the Subject parameter.
Worked example, using the warning payload from the reported flow:
{"subject":"Warning message","message":"The temperature has reached 30deg"}
Counted as bytes: 1 for the opening brace, 9 for "subject" with its quotes, 1 for its colon, 17 for "Warning message" with its quotes, 1 for the comma, 9 for "message" with its quotes, 1 for its colon, 35 for the warning sentence with its quotes, and 1 for the closing brace — 1+9+1+17+1+9+1+35+1 = 75 bytes. The default ceiling is 256 KiB, and 256 × 1024 = 262,144 bytes, so the payload uses 75 ÷ 262,144 ≈ 0.0003 of it, about 0.03 percent. Size is never why the email disappears: the same 75 bytes deliver in raw mode and are rejected in JSON mode, because the object's keys are not the protocol entries the structure requires.
The Subject input carries its own documented constraints, a length ceiling and character restrictions, published alongside Message and MessageStructure on the same API reference page. Keep alarm subjects short, plain and free of formatting characters, and hold the final wording against those limits before the first production send.
How do you verify the new subject without duplicate emails? #
Verify the boundaries one at a time: an accepted MQTT publish proves the MQTT hop, an accepted Publish call proves SNS accepted the request, and only the delivered email's subject line proves the fix — disable the old direct action first so one event cannot travel both routes.
- Record the baseline: save the Node-RED flow, the IoT rule, and one delivered raw-mode email with its default subject.
- Disable the old direct-to-SNS action before enabling the new route, so a single event cannot travel both paths.
- Publish one controlled test event carrying the subject string and the warning text as two payload fields; confirm the rule forwards both unrenamed and unnested.
- Confirm the outgoing Publish call carries Subject and Message as two separate inputs, not as one combined text.
- Read the delivered email: the subject line equals your string and the body equals the warning text. An accepted publish response with no email arriving points at the subscription or the mailbox, not at the subject mapping.
A level-based trigger publishes on every reading above the limit, so a long warm period produces a stream of identical emails. One email per threshold crossing needs transition logic on the Node-RED side, publishing on the flip rather than on every qualifying reading.
Questions asked
Does the Publish Subject parameter affect anything besides email?
Its documented purpose is the subject line for deliveries to email endpoints. Transports without a subject concept receive the message text without it. Fill it whenever the topic serves an email subscription; where only non-email transports consume the topic, the message body alone carries everything you need.
When is the SNS JSON message structure the right choice?
MessageStructure set to json exists for one publish that must carry different text per transport protocol: each entry in the object names a delivery protocol, and a fallback entry covers every protocol without its own text. A single-audience email alarm gains nothing from it, so publish plain text instead.
How do I send one email per threshold crossing instead of one per reading?
Make the Node-RED logic edge-triggered: store the previous comparison result, for example in flow context, and publish only when it changes from below the limit to at or above it. A level-based rule publishes on every qualifying reading, so a warm period that lasts hours would send an email per scan interval.
Can the Node-RED host stay free of SNS permissions entirely?
Yes, and that is the server-side publisher route: Node-RED keeps publishing MQTT only, the IoT rule hands the event to a publisher function, and that function's execution identity is the only principal allowed to publish to the SNS topic. The Node-RED host then holds no credentials capable of sending email.