This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Plain text email has new line characters instead of formatting


I am encountering one problem with one of my action in stackstorm where email formatting still has newline characters. It is python runner where I send email in plain-text or html format, depending on input:

def run(self, toEmail, fromEmail, body, subject, isHTML=False, ccEmail=None):


Run method to send email.


smtpObj = smtplib.SMTP('localhost')

if isHTML:

  message = MIMEText(str(body), 'html')


  message = MIMEText(body, "plain")

message['To'] = toEmail

message['From'] = fromEmail

message['Subject'] = subject

message['cC'] = ccEmail

smtpObj.sendmail(fromEmail, [toEmail, ccEmail], message.as_string())

Has anyone seen this issue before in Stackstorm? Any help is appreciated.


Anand S.

How are you calling this method? From somewhere else in the Python action, or is this a standalone action that you’re calling as part of a workflow?

What content are you calling this action with?

If it is a standalone action, what happens if you just call the action directly, bypassing any workflows?

My guess is that you’ve probably got double-escaping going on somewhere. Would need to see the wider context of how you’re using this action.


I have tested this action standalone as well to isolate the issue and this is how I test it:

st2 run sre_common.email_notification body=‘This \n is my \n sample \n email test.’ fromEmail=‘[email protected]’ subject=‘Provisioning Completed for Order ID : 1521030191420’ toEmail=‘[email protected]’ isHTML=‘false’

This is what I get in my inbox:
This \n is my \n sample \n email test.

Anand Sengar

Escaping the unicode encoding and encoding back in utf-8 solved my problem.

Basically adding one line like this:

message._payload= message._payload.decode('unicode_escape').encode('utf-8')

Thanks for all the help and suggestions.
Anand S.

Great to hear you got it working