As SharePoint developers, we are often asked to streamline processes for end users. One common task is providing a quick way to send prefilled emails with dynamic content straight from a SharePoint list. In this blog post, I will guide you through a simple JSON formatting solution that opens a new Outlook email window with a pre-populated recipient, subject, and body—automatically based on list item data.
The Problem
Imagine you manage a SharePoint list that tracks orders. You need to quickly initiate emails to different customers, with relevant order details embedded in the subject and body of the email. Instead of manually copying this information every time, wouldn’t it be more efficient to automate it?
This is where SharePoint column formatting with JSON comes into play.
The Solution: JSON Column Formatting
With JSON column formatting, you can customize the display of your SharePoint list columns to create clickable elements. In this case, a hyperlink will trigger Outlook to open a new message window, prefilled with essential information, including the recipient’s email, order number, and a custom message. (In my example, I have a list of orders so I include the order number).

Here’s the JSON code:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"children": [
{
"elmType": "a",
"attributes": {
"href": "= 'mailto:' + [$Item_email] + '?subject=Lån ' + [$Item_order_number] + '&body=Hi,%0D%0A%0D%0ALorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt sapien eu ex aliquam posuere. Phasellus non lobortis mauris. Ut non tincidunt nibh nr ' + [$Item_order_number] + '. In turpis nisl, molestie nec feugiat at, placerat non leo. Suspendisse nunc sem, consectetur venenatis sem non, pulvinar sollicitudin ex. Aenean vitae quam interdum, auctor augue non, posuere tellus. Proin iaculis ornare bibendum. Aliquam lacinia eu ex ac sagittis. %0D%0A%0D%0A\"Link to more info\": https://www.test.com/info'",
"target": "_blank",
"class": "sp-link",
"title": "Initiera mejl"
},
"children": [
{
"elmType": "span",
"style": {
"font-size": "16px",
"padding": "5px 10px",
"color": "#333"
},
"attributes": {
"iconName": "Mail"
}
}
]
},
{
"elmType": "span",
"txtContent": "[$Title]"
}
]
}
How It Works
- The
hrefattribute: This is where the magic happens. Using SharePoint JSON formatting, themailto:scheme is used to initiate an email.- The
tofield is filled with the email stored in the[$Item_email]column. - The
subjectcontains the order number dynamically pulled from the[$Item_order_number]column. - The
bodypre-populates with a structured message, which can also include a link to further information, such as a web page or document.
- The
- Styling and accessibility: The link is wrapped in a styled
spanelement to ensure it looks appealing, with a mail icon that gives users a visual cue. Additionally, setting thetargetattribute to"_blank"ensures the mail window opens without leaving SharePoint.
Customizing for Your Needs
Change the Email Body: You can easily modify the body text to suit your needs. Simply edit the &body=Hi,%0D%0A... part of the code, making sure to URL-encode any special characters or line breaks (%0D%0A represents a new line).
Add More Data: Want to include more list item details in the email? No problem. Simply concatenate additional columns in the href attribute as needed, like this:
"href": "= 'mailto:' + [$Item_email] + '?subject=Update on ' + [$Item_project] + ' - ' + [$Item_order_number]"
Enhance the Look: The code provides basic styling for font size, padding, and color, but feel free to further enhance the look of the link and icon to better match your SharePoint site’s theme.
Limitations
While this method is quick and easy, it does have a few limitations:
- Email Client Dependence: This solution depends on the user having an email client (like Outlook) set up to handle
mailtolinks. Users relying purely on web-based clients like Gmail may experience a different flow. - Security Concerns: Ensure that dynamically populating the recipient’s email address is done securely, particularly if your list contains sensitive information.
Conclusion
With just a few lines of JSON, you can transform a simple SharePoint list column into an actionable email trigger, saving time and reducing errors in manual email creation. This solution is not only functional but also customizable, ensuring it can fit various business needs.
As always, feel free to experiment with the code and adapt it to suit your specific requirements. JSON column formatting in SharePoint is a powerful tool that allows us to deliver dynamic, user-friendly interfaces with minimal effort.
Happy coding!