Add Random Email Signature To Mail Action

I’m like to pull a random line of text from an existing draft to include as an email signature when creating an email using the Email or Markdown Email actions.

Being new to Drafts and having no programming knowledge, I’m struggling to figure this out. I think that I somehow need to reference a random line in my “Quotes” draft which is separated by carriage returns.

I’ve searched for “random” “quote” and variations in the forum, have gotten to some close posts about adding quotes to daily journal templates but they were built with Shortcuts.

Can anyone offer some suggestions or point me to resources to learn?

This is not a complete solution, but should get you started…

// load your quote draft into a variable
// you can copy the identifier of the draft from the context menu 
// in the draft list
let d = Draft.find("UUID-OF-DRAFT")

// select a random line from the draft
// the `lines` property of a draft is an array of its lines, separated by line feeds
const randomLine = d.lines[Math.floor(Math.random() * d.lines.length)];

// create a template tag to use in a later email step
// this creates a `[[quote]]` tag you can use in an action steps after this script
// in the same action, like an email step
draft.setTemplateTag("quote", randomLine)

I’m learning…

I was able to find the UUID of the draft containing the hundreds of quotes. I was able to figure out that I needed to add the script action prior the mail action and did so.

Now I’m just stuck on a formatting issue – the [[quote]] tag is after my contact information on what I thought would be a new line, but it seems to be disregarding the “return” key. EDIT: I just noticed that it seems to skipping the returns between my name and phone number too.

Any tips?

There are scenarios where Markdown line breaks have not properly been defined and where e-mail can lose their new lines.

If you duplicate your action and sanitise it by changing any personal details you don’t wish to share on a public forum to fictitious details, you can then share it as an unlisted action to the directory, post the link here, and we can take a closer look.

I think this is correct…first time sharing an action.

The body you have specified is your mail action is this.


John Esher, Jr.
(267) 239-4476


The mail action also has this option set.


So you need to define everything in HTML for your e-mail.

The %%[[body]]%% takes the body of the draft and the four percentage symbols indicate that the body tag content should be interpreted as Markdown and converted to HTML.

The remaining content isn’t defined as or converted into HTML, so it just gets output as one long string of text.

The quotation tag can make use of the same quadruple percentage symbols to convert that into HTML.

The name and number are not in a tag, so for that, the easiest thing is to pop the HTML in directly. We can wrap them in a paragraph block and put a line break tag in to force the line break.

Try substituting in the following for the mail action body.


John Esher, Jr.<br>
(267) 239-4476

1 Like

Thanks for the lesson and the solution, it works perfectly!

1 Like