Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Send-RjRbReportEmail

Send branded HTML report emails from Azure Automation runbooks via Microsoft Graph using Markdown content.

Overview

Send-RjRbReportEmail is the standard helper for delivering report emails from RealmJoin reporting runbooks. It takes Markdown content, converts it to a RealmJoin-branded responsive HTML email, attaches optional files and inline branding graphics (header/footer), and sends the result through the Microsoft Graph sendMail endpoint.

Renamed in this release. The function was renamed from Send-RjReportEmail to Send-RjRbReportEmail for naming consistency with the rest of the module (*-RjRb*). The old name Send-RjReportEmail is exported as a backwards-compatible alias, so existing runbooks keep working unchanged — but new runbooks should call Send-RjRbReportEmail.

Key characteristics:

  • Markdown in, HTML out — runbooks compose the report body in Markdown; the function renders it to themed HTML that works across Outlook Classic, New Outlook, Outlook Web, mobile clients and dark mode.

  • One email per recipient — when multiple recipients are supplied, the function sends an individual message to each address rather than a single multi-recipient mail. This is a privacy/BCC-by-default design.

  • Inline branded header & footer — bundled PNG assets are sent as CID attachments and referenced by the embedded HTML. Both can be overridden or suppressed entirely.

  • Customizable template colors — the accent and text color of the template can be overridden per call, so report emails can follow a customer's corporate design.

  • Built-in attachment size guard — an optional smaller fallback attachment set is sent automatically when the regular set exceeds the size budget or its send attempt fails.

  • Self-connecting — if no Graph session is active, the function transparently calls Connect-RjRbGraph (or Connect-MgGraph -Identity when -UseNativeGraphRequest is set).

  • Resilient — failed attachment reads, invalid image overrides, invalid colors, or per-recipient sendMail failures are reported but do not abort the entire batch unless all recipients fail.

Centralized email settings (sender address, service desk info) are documented in Runbook Report Settings — this document focuses on calling the function from a runbook.

Prerequisites

Sender mailbox

A licensed Microsoft 365 mailbox (typically a dedicated shared mailbox such as realmjoin-report@contoso.com) is required as the From address. The Automation Account's managed identity must be allowed to send on behalf of that mailbox via the Graph Mail.Send application permission (scoped via RBAC for Applications if you want to restrict the identity to a single mailbox).

The sender must not be a Microsoft 365 group. The function sends via the Graph endpoint /users/{EmailFrom}/sendMail — a Microsoft 365 group is not a user object, so the call fails. Use a user or shared mailbox.

Microsoft 365 group addresses as recipients are technically accepted, but not recommended: the message may only reach the group mailbox (members get a personal copy only if they follow the group), the group's delivery management may reject the sender, and delivery failures surface only as an NDR in the sender mailbox — the runbook itself still reports success. Prefer individual mailbox addresses.

Graph permissions

Scenario
Required permission

Default (Invoke-RjRbRestMethodGraph)

Mail.Send (Application) on the sender mailbox

With -UseNativeGraphRequest

Same — the call still hits /users/{id}/sendMail

Module connectivity

By default the function uses Invoke-RjRbRestMethodGraph from this module. If no connection is active it auto-connects via Connect-RjRbGraph. When -UseNativeGraphRequest is set, the function instead checks Get-MgContext and calls Connect-MgGraph -Identity -NoWelcome on demand.

Quick Start

The minimum viable call requires only the sender, the recipient, a subject and the Markdown body:

This produces a fully branded RealmJoin email with the default header and footer, light/dark mode support, and the tenant/version block in the footer.

Parameters

Required

Parameter
Type
Description

EmailFrom

string

User principal name or object id of the sender mailbox. Used as /users/{id}/sendMail. Must be a user or shared mailbox — a Microsoft 365 group is not a user object and the send fails.

EmailTo

string

Recipient address. Single string — multiple addresses are passed as a comma-separated list, see below. Microsoft 365 group addresses are accepted but not recommended — delivery to members is not guaranteed and failures are not visible to the runbook.

Subject

string

Subject line. Also injected into the HTML <title> element.

MarkdownContent

string

Report body in Markdown. See Markdown Support for the supported syntax.

Optional — Content

Parameter
Type
Default
Description

Attachments

string[]

@()

Local file paths to attach. Missing files are logged and skipped, unreadable files emit a warning but do not abort the send. MIME type is derived from the file extension.

saveToSentItems

bool

$true

If $true the sent message is kept in the sender mailbox's Sent Items. Set to $false for high-volume reporting to avoid filling the mailbox.

TenantDisplayName

string

—

Shown in the tenant-info box embedded at the end of the content area.

ReportVersion

string

—

Shown in the tenant-info box (use semantic version strings, build numbers, or a runbook name + date).

Optional — Branding

Parameter
Type
Default
Description

HeaderImage

string

bundled Assets/Header.png

Local file path to a PNG/JPG/GIF that overrides the default header graphic. The runbook must resolve any URL/blob to a local file beforehand (e.g. via Get-AzStorageBlobContent). Missing/unreadable overrides fall back to the bundled default and emit a warning.

FooterImage

string

bundled Assets/Footer.png

Same handling as HeaderImage. The footer is rendered as a single clickable image — any branding text, logo or URL must be baked into the PNG.

FooterLink

string

https://www.realmjoin.com

URL used as the href and title of the anchor wrapping the footer image.

NoHeader

switch

off

Suppresses the header graphic entirely. If combined with HeaderImage, a warning is emitted and the override is ignored.

NoFooter

switch

off

Suppresses the footer graphic and its link entirely. If combined with FooterImage or a custom FooterLink, a warning is emitted and those values are ignored.

AccentColor

string

#f8842c

New in 0.8.9. 6-digit hex color for table header rows, action buttons and the accent borders of the info boxes. An empty or malformed value emits a warning and falls back to the default.

TextColor

string

#011e33

New in 0.8.9. 6-digit hex color for body text, headings, list items and code. Same fallback behavior as AccentColor.

Recommended image dimensions: 750 × 200 px PNG. This matches the email container width and the bundled defaults. Significantly different aspect ratios may look distorted on narrow viewports. Each graphic should stay well below 3 MB — Graph caps the total sendMail request at 4 MB and a warning is emitted if either image exceeds 3 MB.

Colors: without AccentColor/TextColor the generated HTML is byte-for-byte identical to previous module versions — the defaults are the RealmJoin orange and navy. Status colors (green/red/amber) and neutral grays are intentionally not parameterized because they convey meaning. Verify custom colors in both light and dark mode: the content card stays white in dark mode, so a very light text color becomes unreadable.

Optional — Attachment size guard

New in 0.8.9. Graph rejects the whole sendMail request once the message exceeds ~4 MB. Instead of failing the report, the function can fall back to a smaller attachment set. This logic was previously duplicated as the inline runbook helper Send-RjRbGuardedReportEmail and is now part of the function itself.

Parameter
Type
Default
Description

FallbackAttachments

string[]

—

Smaller attachment set used when the regular set exceeds MaxAttachmentBytes, or when the send with the regular set fails for every recipient. Without this parameter there is no fallback and a failed send throws immediately.

FallbackMarkdownContent

string

value of MarkdownContent

Body used when the fallback set is sent — use it to explain which files were left out and how to obtain them.

MaxAttachmentBytes

long

2.5MB

Raw size budget for the regular attachment set. Stays safely below the ~4 MB Graph limit after base64 encoding (+33 %), HTML body and inline branding images. Only evaluated when FallbackAttachments is supplied.

The guard runs in two stages:

  1. Before sending — if the regular set exceeds the budget, the fallback set is sent directly and a message names both sizes.

  2. After a failed send — if the send with the regular set fails for all recipients, one retry with the fallback set is attempted before the function throws.

Optional — Transport

Parameter
Type
Default
Description

UseNativeGraphRequest

switch

off

Sends via Invoke-MgGraphRequest (requires Microsoft.Graph module and a Connect-MgGraph session) instead of Invoke-RjRbRestMethodGraph. Use this when the runbook is built around the native SDK rather than the RealmJoin wrapper.

Usage Examples

Multiple recipients

EmailTo accepts a single string containing one or more comma-separated addresses. Each address is trimmed, empty entries are removed, and one individual email is sent per recipient — recipients do not see each other.

With attachments and tenant metadata

The attached files are listed in an "Attached Files" box at the bottom of the email body, in addition to being added as real attachments to the message.

Bring your own branding by downloading the assets to a local path first, then pass the resulting paths. The function does not fetch URLs itself.

If $headerPath is missing or unreadable, the call still succeeds — the bundled RealmJoin default is used and a warning is logged.

Custom template colors

Match the email to a customer's corporate design. Both parameters are independent — overriding only the accent color keeps the default text color:

An invalid value (for example blue or #05c) does not fail the send: a warning names the parameter and the default color is used.

Large reports with a fallback attachment set

Generate a CSV and an Excel workbook, but fall back to the workbook alone when the pair exceeds the size budget:

Runbooks migrating from the inline helper Send-RjRbGuardedReportEmail can drop that function and rename the call to Send-RjRbReportEmail — the parameter names (Attachments, FallbackAttachments, FallbackMarkdownContent, MaxAttachmentBytes) are unchanged.

For alert-style notifications that should not look like a marketing email:

Using the native Microsoft.Graph SDK

If the runbook is already authenticated through Connect-MgGraph (managed identity) and you prefer not to mix in the RealmJoin wrapper:

Reading the report body from a file

For larger reports, generate the Markdown to a .md file and read it in:

Action buttons (call-to-action)

Render one or more branded buttons by appending {button} to a Markdown link. Buttons placed on the same line are grouped into a single row:

Each button is a normal hyperlink styled as a CTA — safe in all clients, with rounded corners in modern clients and square corners in Outlook Classic.

Markdown Support

The function ships with a built-in lightweight Markdown → HTML converter. No external Markdown module is required. Supported syntax:

Markdown
Notes

# … ###### headings

All six levels. Space after # is optional. h1 gets an underline; spacing tuned for Outlook.

**bold**, *italic*, ~~strike~~

Inline-only (must not span multiple lines).

`inline code`

Rendered as <code> with a light grey background.

lang ... fenced code blocks

Language tag is preserved as class="language-…". Also tolerates malformed single-backtick fences.

[text](url) links

Open in new tab with noopener noreferrer.

[label](url){button} link buttons

Rendered as a branded orange call-to-action button instead of a plain link. Multiple {button} links on the same line render side by side in one row (width split equally). Rounded corners show in modern clients (New Outlook, OWA, mobile); Outlook Classic (Word engine) renders square corners.

![alt](url) images

Inserted as <img> (no inline-attachment magic — the URL must be reachable by the mail client).

- item / 1. item lists

Nested lists supported via 2-space indentation per level. Mixing ordered and unordered closes the previous list.

Multi-line list items

An indented, non-empty line directly under a <li> is folded into the same item with a <br> soft break — no need to keep each item on one line.

- [ ] / - [x] task lists

Rendered as ☐ / ☑ Unicode glyphs (green when checked). <input type="checkbox"> is intentionally avoided because Outlook Classic strips form controls. Capital [X] also counts as checked.

> blockquote

Rendered with a coloured left border and shaded background.

> [!NOTE|TIP|IMPORTANT|WARNING|CAUTION]

GitHub-style admonitions. First line of the blockquote is the marker (alone), the remaining >-prefixed lines are the body. Each type gets its own accent colour, glyph and title bar.

---, ***, ___

Horizontal rule.

|col|col| tables

Standard pipe tables with :---, :---:, ---: alignment specifiers. Header row + separator required.

\\ escaping

\*, | etc. are honoured so literal Markdown characters can be emitted.

Items not supported include footnotes, definition lists, and HTML pass-through — keep the Markdown to the table above.

Behavior & Error Handling

Recipient parsing

EmailTo is split on commas, each entry is trimmed and empty entries are dropped. If the resulting list is empty the function throws No valid email recipients found in EmailTo parameter. before any Graph call is made.

Per-recipient failures

Each recipient is sent independently. The function tracks successes and failures:

  • If at least one send succeeds but others fail, a warning is emitted listing the failed addresses; the function returns normally.

  • If all sends fail, the function throws Failed to send email to all recipients: … so the runbook fails loudly.

Attachment failures

  • Missing files (path does not exist) — logged verbosely, silently skipped.

  • Existing but unreadable files (locked, permission denied) — warning emitted, skipped, the rest of the call proceeds.

  • The "Attached Files" box at the bottom of the email lists only attachments that were successfully read.

Image override failures

Both HeaderImage and FooterImage fall back to the bundled defaults on any error (missing file, IO error, or a file that is not a valid image). A warning describes the failure and identifies which default was used.

Since 0.8.9 the image format is determined from the file signature (magic bytes) rather than the file extension. A file that is named .png but actually contains an HTML error page — a common outcome when a download silently returns an error document — is now rejected with a warning instead of producing a broken inline attachment. Conversely, a valid PNG saved under a misleading extension is accepted and typed correctly.

Invalid colors

AccentColor and TextColor are validated against ^#[0-9A-Fa-f]{6}$. A value that does not match emits a warning naming the parameter and the send proceeds with the default color. Colors are never a reason for a report to fail.

Total size limit

Graph caps sendMail requests at ~4 MB combined (HTML body + all attachments, base64-encoded). The function emits a warning when either branding image exceeds 3 MB.

When FallbackAttachments is supplied, the attachment size guard described in the parameter section above handles oversized payloads automatically. Without a fallback set, an oversized request fails in the Graph call; consider:

  • Supplying a FallbackAttachments set (for example the Excel workbook without the raw CSV files).

  • Uploading large data to the Storage Account channel instead — see Runbook Report Settings.

  • Linking to externally hosted attachments rather than embedding them.

  • Compressing tabular data (Compress-Archive) before attaching.

Integration with Runbook Report Settings

Reporting runbooks do not hard-code the sender address or branding: they declare hidden parameters that the RealmJoin portal prefills from the central customization JSON. The available settings are documented in Runbook Report Settings.

The binding happens in the runbook's param() block via Use-RJInterface -Type Setting, and the parameters are marked "Hide": true in the .INPUTS RunbookCustomization block so they do not clutter the portal form:

See Get-RjRbBrandingMailParams for the download, validation and cleanup rules.

Outputs

The function returns nothing on success. All progress is written via Write-RjRbLog -Verbose (visible when the runbook is run with -Verbose or $VerbosePreference = 'Continue'). Warnings are forced through $WarningPreference = 'Continue' regardless of caller-side overrides, so they reliably appear in the Azure Automation job stream.

The building blocks behind Send-RjRbReportEmail are now exported from the module too, so runbooks can compose or preview the HTML without sending:

Function
Purpose

Turns the RJReport.Branding.* tenant settings into ready-to-splat parameters: downloads and validates the images, passes colors and footer link through.

ConvertFrom-RjRbMarkdownToHtml

Standalone Markdown → HTML converter (the same lightweight engine used internally, including the {button} syntax). Accepts -AccentColor/-TextColor.

Get-RjRbReportEmailBody

Assembles the full branded HTML body (header/footer, tenant-info box, attachment list) from HTML or Markdown — useful to render and inspect the email before sending. Accepts -AccentColor/-TextColor.

Resolve-RjRbImageSource

Resolves a header/footer image path to its inline CID source. Validates by file signature and throws on anything that is not a PNG, JPEG or GIF.

Except for Get-RjRbBrandingMailParams, these are primarily intended for advanced/testing scenarios; the normal path is to call Send-RjRbReportEmail directly.

See Also

Last updated

Was this helpful?