Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Teams
, (opens new window)

One Appfire Support Knowledge Base
Results will update as you type.
  • License-related documentation
  • Product Categories
    • Administrative Tools
    • BI and Reporting Apps
    • Publishing
    • Agile
    • Document Management
    • ITSM
    • Developer Tools
    • Workflow & Automation
      • Jira Misc Custom Fields
      • JMWE for Jira Server and Data Center
      • JMWE for JIRA Cloud
      • Power Scripts for Confluence
      • Power Scripts Knowledge Base
        • Scripting Best Practices
        • Troubleshooting Power Scripts
        • Scripting Basics
        • Live Fields Articles
        • Finding Kepler Home and SIL Templates
        • Code Snippets
          • Converting Milliseconds to Days
          • Creating a Sum of Custom Field Values
          • Creating a Table in the Description
          • JSONifying a String with Unusual Dimensions
          • Preparing Data for Use with lfRestrictSelectOptions()
          • Preventing an Epic from Closing Until All Children Are Closed
          • Prevent Sub-task Creation in Jira Cloud
          • Running Scripts Via REST
          • Using HTML with sendEmail()
          • Using the split() Routine
          • Working with JSON Data
          • Chaining Filters in a Jira Expression
          • Using AJAX to Hide Issue Links
          • Retrieving Data From a Separate File
          • Using Atlassian Wiki Markup to Create a Table in the Description
          • Using the Jira Announcement Banner on Screens Where Live Fields is not Supported
          • Bulk user account deactivation (last-login-based)
          • How to fetch the fixVersions ID from an issue using SIL routines and the JVersion structure
          • Select List (single choice) options description+id in Power Scripts using SIL Groovy Connector/Runner
        • Common REST Service Security Settings
        • REST, cURL and Postman
        • How to set admin token in Power Apps
        • LDAP configuration settings for SSL connections in Power apps config
      • JQL Search Extensions for Jira
      • JSU Automation Suite for Jira Workflows- Server / Data Center
      • JSU Automation Suite for Jira Workflows - Cloud
      • Autowatch for Jira
      • Power Database Fields PRO Knowledge Base
      • Scripting for Confluence (SCRP)
      • JIRA Command Line Interface (CLI) (JCLI)
      • Update on Transition for JIRA (CW)
      • UPM Command Line Interface (CLI) (UPMCLI)
      • Service Desk Command Line Interface (CLI)
      • Tempo Command Line Interface (CLI)
      • Bitbucket Command Line Interface (CLI)
      • Create on Transition for JIRA (CSOT)
      • Confluence Command Line Interface
      • Run CLI Actions in Confluence (CCLI)
      • Bamboo Command Line Interface (CLI) (BCLI)
      • Run CLI Actions in JIRA (JCLIP)
      • Clone Plus for JIRA (JCPP)
      • Run CLI Actions in Bamboo (BCLIP)
      • Atlassian Command Line Interface (CLI) (ACLI)
      • Agile Command Line Interface (CLI) (AGILECLI)
      • How to retrieve debug logs for Clone Plus for Jira, Create on Transition, and Update on Transition apps in Jira
    • Integrations KB's
  • Migration Support
  • General Articles
  • KB [KBS]
    You‘re viewing this with anonymous access, so some content might be blocked.
    /
    Using HTML with sendEmail()
    Published Nov 21, 2022

    Using HTML with sendEmail()

    sendEmail() supports HTML. Great, but how does one construct the HTML so that it works? Find out by reading below!

    Background

    There are many guides and tutorials much better than we could cover here. To get started, visit any popular tutorial website dealing with HTML. 

    GeeksforGeeks - HTML Tutorials

    The basic HTML accepted is in the following format:

    <html><body> <p>Hello Tim,</p> <p></p> <p>Nice conversation we had the other day!</p> </html></body>

    Basically the idea is that the HTML starts with "<html><body>" and ends with "</html></body>". You can pretty much add any elements you wish in between.

    String Concatenation

    A basic feature of the SIL Language is that you can concatenate (that is, combine) two strings together like this:

    string stringCombo = "Nice conversation " + "we had the other day!"

    If we were to print this out, it would read, "Nice conversation we had the other day!" Let's say we wanted to switch up what we would like to say, so we can configure "stringCombo" to say, "Nice discussion we had the other day!"

    string typeofMeeting = "discussion"; string stringCombo = "Nice " + typeofMeeting + " we had the other day!"

    Now that we have the basics of string concatenation out of the way, let's see how we can use this with HTML.

    Code Example 1 - Passing Data Via a Variable

    Joining strings together is no different when using HTML. However, it may be a bit more complicated because we now much be careful with HTML syntax. I find it useful to print out what the string will actually look like once the string variables have been processed. For that, use the runnerLog() routine when testing scripts in the SIL Manager. If it turns out there is too much text to read in the console, consider using printInFile() or logPrint().

    string body;   string formattedCurrentDate = formatDate(currentDate(), "yyyy.MM.dd HH:mm"); string formattedCreatedDate = formatDate(created, "yyyy.MM.dd HH:mm");   body = "<html><body>"; body += "<p>" + formattedCurrentDate + "</p>"; body += "<p>" + formattedCreatedDate + "</p>"; body += "</html></body>";   runnerLog(body);

    Code Example 2 - Creating a Link

    A common use case when sending email is to send issue links. To make this work, modify the link so that it reflects the url path as found on your Jira instance. For example, on my test instance, links to an issue look like this: http://localhost:8080/browse/EX-1

    string body;   body = "<html><body>"; body += "<p>test</p>"; body += "<a href=\"https://<BASE URL>/browse/" + key + "\">" + key + "</a>"; body += "</html></body>";   sendEmail("first.last@example.com", "subject", body);

    Code Example 3 - Add Styling to the HTML for Visual Affects

    You can make any modification to the HTML using css. For example, let's say we wanted the dates (as defined below) to read in a blue color

    string body;   string formattedCurrentDate = formatDate(currentDate(), "yyyy.MM.dd HH:mm"); string formattedCreatedDate = formatDate(created, "yyyy.MM.dd HH:mm");   body += "<html>"; body += "<head>"; body +=   "<style>"; body +=     "p {"; body +=       "color: blue;"; body +=     "}"; body +=   "</style>"; body += "</head>"; body += "<body>"; body += "<p>" + formattedCurrentDate + "</p>"; body += "<p>" + formattedCreatedDate + "</p>"; body += "</html></body>";   sendEmail("first.last@example.com", "subject", body);

    Additional Help

    Need help implementing this script? Talk to me directly to me by clicking on the bot on this page.

    Related articles

    Filter by label

    There are no items with the selected labels at this time.

    {"serverDuration": 14, "requestCorrelationId": "b7fdaca741f142dfb091653059680948"}