- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的脚本中,用户填写 Django 表单,然后执行两件事:数据保存在我的数据库中,并将电子邮件发送到支持帐户。
我正在寻找改进我的 Django Web 应用程序中的这一小部分。所有这些过程都运行良好,但我认为我想改进这部分:
subject = "Ticket n° " + str(post.id) + " : " + str(post.Objet.encode('utf-8'))
message = "Bonjour Datasystems, \n \n Vous avez un nouveau ticket en attente comportant les informations suivantes : \n " + "Nom : " + str(post.Nom.encode('utf-8')) + " \n Prénom : " + str(post.Prenom.encode('utf-8')) + " \n Société/Association client : " + str(request.user.last_name.encode("utf-8")) + " \n N° Téléphone : " + str(post.Telephone.encode("utf-8")) + " \n Adresse Email : " + str(post.Mail.encode("utf-8")) + " \n Description du problème : " + str(post.Description.encode("utf-8"))
image = post.Image
mail = EmailMessage(subject, message, 'support@datasystems.fr', ['support@datasystems.fr'], html_message='This is <b>HTML</b> Content')
mail.attach_file(image.path)
mail.send()
我想在每个变量之前用粗体字符写这部分。
例如在我的电子邮件中:
并在放置 \n
的位置留出垂直空间:
例如:
Bonjour Datasystems,
Vous avez un nouveau ticket ... (currently)
---
Bonjour Datasystems,
Vous avez un nouveau ticket ... (What I would like to get)
到目前为止,我的电子邮件如下所示:
针对我的这两个问题,你们有什么解决办法吗?
最佳答案
制作两个模板;我们将文本版本称为 message.txt
,将 html 版本称为 message.html
。渲染它们并将结果传递给 EmailMessage()
:
from django.template.loader import get_template
context = {
'Nom' : str(post.Nom.encode('utf-8')),
'Prenom' : str(post.Prenom.encode('utf-8')),
'Telephone' : str(post.Telephone.encode('utf-8')),
'Email' : str(post.Mail.encode('utf-8')),
'Objet' : str(post.Objet.encode('utf-8')),
'Description' : str(post.Description.encode('utf-8')),
'Client' : str(request.user.last_name.encode("utf-8")),
}
message = get_template('message.txt').render(context)
html_message = get_template('message.html').render(context)
subject = "Ticket n° " + str(post.id) + " : " + str(post.Objet.encode('utf-8'))
image = post.Image
mail = EmailMultiAlternatives(subject, message, 'support@datasystems.fr', ['support@datasystems.fr'])
mail.attach_alternative(html_message, "text/html")
mail.attach_file(image.path)
mail.send()
示例message.txt
:
Bonjour Datasystems,
Vous avez un nouveau ticket en attente comportant les informations suivantes :
Nom : {{ nom }}
foo : {{ bar }}
示例message.html
:
<html>
<body>
<h1>Bonjour Datasystems,</h1>
<p>Vous avez un nouveau ticket en attente comportant les informations suivantes :</p><br><br>
<p>
<strong>Nom</strong> : {{ nom }}<br>
<strong>foo</strong> : {{ bar }}
</p>
</body>
</html>
关于python - 使用 Django EmailMessage 将文本设置为粗体和垂直空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45215007/
我正在尝试使用 django.core.mail 使用默认后端发送电子邮件,但它似乎不起作用。我已经在设置文件中设置了电子邮件凭据、服务器和端口号,但是每当我尝试运行电子邮件消息的 send() 方法
我已经知道如何使用 Django EmailMessage 对象发送电子邮件: msg = EmailMessage(title, body, from, [to], headers=headers)
我必须检索已发送电子邮件的正文并将其存储在共享文件夹中。我有以下代码示例来从电子邮件中检索附件并存储它。 EmailMessage message = EmailMessage.Bind(servic
我正在尝试设置一个自动电子邮件发送脚本。我正在使用电子邮件模块和 EmailMessage来自 email.message 的对象模块并正在使用 smtplib 发送电子邮件模块。我希望能够将 .pd
有没有办法使用 EWS 准确识别邮箱中退回的电子邮件通知?到目前为止,我已经查看了邮件标题,似乎没有任何迹象表明该邮件是电子邮件退回通知。 我也看了 Item 和 EmailMessage 成员并没有
在我的脚本中,用户填写 Django 表单,然后执行两件事:数据保存在我的数据库中,并将电子邮件发送到支持帐户。 我正在寻找改进我的 Django Web 应用程序中的这一小部分。所有这些过程都运行良
我正在使用 Java EWS API(EWS - Exchange Web 服务)从 Exchange 服务器获取电子邮件并将其存储在专有 CMS 中。我收到消息的类型是 microsoft.exch
我正在使用 EmailMessage 通过 Django 中的 Amazon SES 发送电子邮件。我目前在消息中插入新行时遇到问题。 “\n”似乎不起作用 我该如何去做呢? 举个例子,这是我尝试过的
我正在使用 EWS Managed API 2.0。此时我可以将 EmailMessages 作为 *.eml 文件保存到我的硬盘。但是我无法正确打开它们来显示内容。 如何将 EmailMessage
我正在处理一个使用 Django 1.7 的现有项目我们正在将我们的电子邮件服务与 Amazon Ses 集成。这引发了一个问题,即我们无法监控哪些邮件发送成功,哪些邮件发送失败。所以我正在考虑记录电
我的目标是获取消息参数(发件人、收件人、正文、主题等)并创建一个 .eml 文件。 我目前正在使用 EWS 托管 API(尽管我对其他建议持开放态度)来创建 EmailMessage 对象。我不想将消
如何使用 EWS 或其他方法更新 EmailMessage 的 IsRead 属性? 只是设置 mail.IsRead=true 似乎不会持续。 最佳答案 好吧,在我发布将近 1 小时后没有人回答我的
我有以下代码可以简单地向电子邮件添加文本: msg = New EmailMessage(Service) With msg .From = New EmailAddress(Config("
我正在尝试将图像显示为用Python发送的邮件的一部分。 Python文档上有一个不起作用的示例。 from datetime import datetime import sys import sm
我正在尝试发送带有嵌入图像的电子邮件(不是作为附件文件)。我能够发送邮件。 我正在使用以下代码发送邮件: internal static void Send(SmtpServerConfigurati
我在settings.py中有如下代码 #EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'sender@gm
我的 Django 项目中有一个简单的 ahref 链接: Notify User 点击它,请求的 URL 是: url(r'^someurl/(?P\w+)/$', login_required(s
我想在通过 ResponseMessage ACTION: ADD ACTION: MINUS MULTIPLY &nbs
因此,当我尝试在 Django 中使用 EmailMessage 发送电子邮件时出现此错误。 UnicodeEncodeError 在/checkout/ 'ascii' codec can't en
我的电子邮件可以正确发送,但在接收方邮件中显示不正确。它看起来像这样: To: =?utf-8?b?..?= MIME-Version: 1.0Content-Type: multipart/mix
我是一名优秀的程序员,十分优秀!