【发布时间】:2023-03-31 23:00:05
【问题描述】:
我正在使用 EmailMessage 通过 Django 中的 Amazon SES 发送电子邮件。我目前无法在消息中插入新行。 "\n" 似乎不起作用
我该怎么做?
例如,这是我尝试过的:
subject= "Test email with newline"
message = "%s %s is testing an email with a newline. \nCheck out this link too: http://www.example.com" % (user.first_name, user.last_name)
from_string = "<support@example.com>"
email_message = EmailMessage(subject, message, from_string, [user.email])
email_message.send()
当我发送这封电子邮件时,我收到:
Michael Smith is testing an email with a newline. Check out this link too:
http://www.example.com
但是,我希望电子邮件的格式如下:
Michael Smith is testing an email with a newline.
Check out this link too: http://www.example.com
【问题讨论】:
-
这只是一个猜测,但您是否尝试过将其设为原始字符串?
message = r"%s %s is testing an email with a newline. \nCheck out this link too: http://www.example.com" % (user.first_name, user.last_name) -
试试this
-
可能还需要两个换行符,因为 HTML。