我面临一个问题,即我的所有文本电子邮件都被压缩在一起,并且在发送过程中没有新行持续存在。
这是代码:
def send_ses_message(email_to, subject, body):
ses = init_ses_internal()
if ses:
ses.send_email(
Source='no-reply@domain.com',
Destination={
'ToAddresses': [
email_to,
],
},
Message={
'Subject': {
'Data': subject,
},
'Body': {
'Text': {
'Data': body,
'Charset': 'UTF-8',
},
'Html': {
'Data': body,
'Charset': 'UTF-8',
},
}
},
ReplyToAddresses=[
'mharris@domain.com', # just in case someone replies to a no-reply@ address I'll receive them
],
ReturnPath='mharris@domain.com', # bounce backs will come to me also
)
return True
我最近尝试强制使用 UTF-8,希望可以让换行符持续存在。之后,我在应该存在新行的地方添加了\n 。
以下是电子邮件的示例:
def send_reset_email(self, email_to, unique_id):
subject = "Company Password Reset"
body = """
Hello!\n\n
We have received a request to reset your password.\n
Please click the link below to proceed with resetting your password. Note: this link will expire in 1 hour.\n\n
http://staging.domain.com/password/reset/{}\n\n
If you did not request this reset you can safely ignore this e-mail.\n\n
Thank you for choosing Company!\n\n
The Company Team\n
www.company.com\n
""".format(unique_id)
send_ses_message(email_to, subject, body)
请让我知道我可以做些什么来确保换行符在 Amazon SES 中保持不变。谢谢!
最佳答案
编辑:我在 Outlook 2013 客户端上遇到了类似的问题。在换行符之前添加一个制表符对我有用。
更换 \n
与 \t\n
或 \t\r\n
How do I format a String in an email so Outlook will print the line breaks?
关于email - Amazon SES send_email 带有空格/换行符的文本正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35416618/