email - Amazon SES send_email 带有空格/换行符的文本正文

标签 email amazon-web-services boto3

我面临一个问题,即我的所有文本电子邮件都被压缩在一起,并且在发送过程中没有新行持续存在。

这是代码:

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/

相关文章:

php - 如何强制电子邮件程序显示使用 php 在 html 电子邮件中发送的图像?

c# - 通过 C# 发送邮件

amazon-web-services - AWS 证书 "https"问题

forms - 使用 Amazon CDN 的 Squarespace 网站表单提交问题

python - 使用 Boto3 Lambda 函数进行 S3 存储桶生命周期配置并收到 MalformedXML 格式错误

python - 如何使用 Bazel 的 py_library 导入参数

python - AWS Lambda : Calling the invoke API action failed with this message: Network Error

c# - 检查电子邮件的 Windows 服务 - IIS/C#

python - 如何使用 Python 在 1 次写入 DynamoDB 中插入对象列表?

php - 如何使用自己的SMTP服务器PHP邮件