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):
python string format boto3
add a comment |
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):
python string format boto3
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
add a comment |
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):
python string format boto3
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):
python string format boto3
python string format boto3
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
add a comment |
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
add a comment |
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)
That's a good option.. But not working in the email o/p..
– Amit
Nov 8 at 20:13
add a comment |
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)
That's a good option.. But not working in the email o/p..
– Amit
Nov 8 at 20:13
add a comment |
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)
That's a good option.. But not working in the email o/p..
– Amit
Nov 8 at 20:13
add a comment |
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)
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)
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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