I have written a code in which I am using aws sns to send email notifications to stake holders via boto3 library.
My issue is that when I wrote the code, I used 4space (or tab) spacing between texts to make it more readable, but when viewing it as an email (gmail), it's showing completely unformatted.
What I need is a way to properly format my email messages
My code:
import boto3
def publish_to_sns(sub, msg):
topic_arn = "<my sns arn>"
sns = boto3.client("sns")
response = sns.publish(
TopicArn=topic_arn,
Message=msg,
Subject=sub
)
def final_status(f_name, row_count, staged_row_count, status):
sub = "Complete [{status}]: Process is complete".format(status=status)
msg = """
Process completed.
------------------------------------------------------------------------------------
Summary of the process:
------------------------------------------------------------------------------------
File Name : {file_name}
Status : {status}
Error : N/A
Rows Read : {r_read}
Rows Staged : {r_staged}
------------------------------------------------------------------------------------
""".format(file_name=f_name, r_read=row_count, r_staged=staged_row_count, status=status)
publish_to_sns(sub, msg)
What I am seeing (the colons are not aligned):
I am able to achieve quite readable formatting by using a simple hack. What I did was I copied the whole string from my IDE, and paste it in my Gmail's (We are using Gmail suite) compose message window.
Then I formated the text to look readable:
Then I pasted the whole string back in my IDE.
And it worked!!!
The notifications seems more readable to stake holders now, and considering the limitation of SNS to send rich text messages, this seems to be a quite easy approach.