Python boto3 SNS email formatting











up vote
0
down vote

favorite












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):



enter image description here










share|improve this question
























  • Aligning text with spaces of course only works if there's a fixed width font. You need to use html tables.
    – James Z
    Nov 8 at 18:18










  • Hi JamesZ, Could you direct me to a link where I could find an example for that?
    – Amit
    Nov 9 at 19:05

















up vote
0
down vote

favorite












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):



enter image description here










share|improve this question
























  • Aligning text with spaces of course only works if there's a fixed width font. You need to use html tables.
    – James Z
    Nov 8 at 18:18










  • Hi JamesZ, Could you direct me to a link where I could find an example for that?
    – Amit
    Nov 9 at 19:05















up vote
0
down vote

favorite









up vote
0
down vote

favorite











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):



enter image description here










share|improve this question















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):



enter image description here







python string format boto3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 18:18









James Z

11.1k71735




11.1k71735










asked Nov 8 at 17:51









Amit

176




176












  • Aligning text with spaces of course only works if there's a fixed width font. You need to use html tables.
    – James Z
    Nov 8 at 18:18










  • Hi JamesZ, Could you direct me to a link where I could find an example for that?
    – Amit
    Nov 9 at 19:05




















  • Aligning text with spaces of course only works if there's a fixed width font. You need to use html tables.
    – James Z
    Nov 8 at 18:18










  • Hi JamesZ, Could you direct me to a link where I could find an example for that?
    – Amit
    Nov 9 at 19:05


















Aligning text with spaces of course only works if there's a fixed width font. You need to use html tables.
– James Z
Nov 8 at 18:18




Aligning text with spaces of course only works if there's a fixed width font. You need to use html tables.
– James Z
Nov 8 at 18:18












Hi JamesZ, Could you direct me to a link where I could find an example for that?
– Amit
Nov 9 at 19:05






Hi JamesZ, Could you direct me to a link where I could find an example for that?
– Amit
Nov 9 at 19:05














1 Answer
1






active

oldest

votes

















up vote
0
down vote













This should help you fix the spaces:



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:
------------------------------------------------------------------------------------
{a:<20} : {file_name}
{b:<20} : {status}
{c:<20} : N/A
{d:<20} : {r_read}
{e:<20} : {r_staged}
------------------------------------------------------------------------------------
""".format(a='File Name', b = 'Status', c = 'Error', d = 'Rows Read', e = 'Rows Staged', file_name=f_name, r_read=row_count, r_staged=staged_row_count, status=status)
print(sub)
print(msg)





share|improve this answer





















  • That's a good option.. But not working in the email o/p..
    – Amit
    Nov 8 at 20:13











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213486%2fpython-boto3-sns-email-formatting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













This should help you fix the spaces:



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:
------------------------------------------------------------------------------------
{a:<20} : {file_name}
{b:<20} : {status}
{c:<20} : N/A
{d:<20} : {r_read}
{e:<20} : {r_staged}
------------------------------------------------------------------------------------
""".format(a='File Name', b = 'Status', c = 'Error', d = 'Rows Read', e = 'Rows Staged', file_name=f_name, r_read=row_count, r_staged=staged_row_count, status=status)
print(sub)
print(msg)





share|improve this answer





















  • That's a good option.. But not working in the email o/p..
    – Amit
    Nov 8 at 20:13















up vote
0
down vote













This should help you fix the spaces:



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:
------------------------------------------------------------------------------------
{a:<20} : {file_name}
{b:<20} : {status}
{c:<20} : N/A
{d:<20} : {r_read}
{e:<20} : {r_staged}
------------------------------------------------------------------------------------
""".format(a='File Name', b = 'Status', c = 'Error', d = 'Rows Read', e = 'Rows Staged', file_name=f_name, r_read=row_count, r_staged=staged_row_count, status=status)
print(sub)
print(msg)





share|improve this answer





















  • That's a good option.. But not working in the email o/p..
    – Amit
    Nov 8 at 20:13













up vote
0
down vote










up vote
0
down vote









This should help you fix the spaces:



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:
------------------------------------------------------------------------------------
{a:<20} : {file_name}
{b:<20} : {status}
{c:<20} : N/A
{d:<20} : {r_read}
{e:<20} : {r_staged}
------------------------------------------------------------------------------------
""".format(a='File Name', b = 'Status', c = 'Error', d = 'Rows Read', e = 'Rows Staged', file_name=f_name, r_read=row_count, r_staged=staged_row_count, status=status)
print(sub)
print(msg)





share|improve this answer












This should help you fix the spaces:



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:
------------------------------------------------------------------------------------
{a:<20} : {file_name}
{b:<20} : {status}
{c:<20} : N/A
{d:<20} : {r_read}
{e:<20} : {r_staged}
------------------------------------------------------------------------------------
""".format(a='File Name', b = 'Status', c = 'Error', d = 'Rows Read', e = 'Rows Staged', file_name=f_name, r_read=row_count, r_staged=staged_row_count, status=status)
print(sub)
print(msg)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 19:39









user2534033

217




217












  • That's a good option.. But not working in the email o/p..
    – Amit
    Nov 8 at 20:13


















  • That's a good option.. But not working in the email o/p..
    – Amit
    Nov 8 at 20:13
















That's a good option.. But not working in the email o/p..
– Amit
Nov 8 at 20:13




That's a good option.. But not working in the email o/p..
– Amit
Nov 8 at 20:13


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213486%2fpython-boto3-sns-email-formatting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)