尝试通过OpenLabs发送邮件模块

openlabs_mail的Python项目详细描述


尝试发送邮件图片::https://secure.travis-ci.org/openlabs/trytond-mail.png?分支=开发
:目标:https://travis ci.org/openlabs/trytond mail

…图片::https://coveralls.io/repos/openlabs/trytond mail/badge.png
:目标:https://coveralls.io/r/openlabs/trytond mail


--------


经常需要从Tryton模块发送电子邮件。此模块提供了一个方便且一致的api来生成电子邮件,从而使生成邮件变得更加容易。此外,该模块还为您提供了一些在发送电子邮件时有用的功能(模板
继承、过滤器)。


安装代码块:sh

pip安装openlabs\u mail

…提示:

请记住安装与trytond版本兼容的版本。


或者可以将该模块作为依赖项添加到您的模块中。代码块:python

fb/tryton.cfg l6>;`
例如。


如果使用setup.py安装模块,请记住将前缀设置为模块的openlabs。来自"销售确认电子邮件模块"的"setup.py文件"https://github.com/openlabs/trytond sale confirmation email/blob/01e0887bfa96044318b0bf7b43094b3ee4a1e2fb/setup.py"l94>;`
是一个很好的示例。

quicks开始
----


下面是一个代码示例,如果您希望在确认销售订单时发送电子邮件


…代码块:python

def confirm(cls,sales):
mail=pool().get('mail.mail')

sage=mail.render_email(
from_email='order-confirmation@mydomain.com',
to=[sale.party.email],
subject='your order is confirmation',
text_template='my_module/emails/order confirmatied.txt',
sale=self,#传递到模板上下文

然后可以使用smtp服务器发送。

…提示:

使用
`电子邮件队列<;https://github.com/openlabs/email queue>;``模块代替。



呈现模板
``````````````````````````````````

电子邮件至少需要指定一个"html"或"text"模板。建议同时指定这两者,因为有些电子邮件客户端希望在可用时显示文本内容。


同时指定文本和HTML部分

。代码块:pythons/honking email.html',



模板名称的格式应为:
`<;模块名称>;/path/to/email/template`.

提示:

复制到站点包并随模块分发



扩展模板(dry)
``````````````````````````````````````

每个业务都是唯一的,它们的电子邮件也应该是唯一的。您可能希望
向模板中添加内容、更改设计或完全覆盖
电子邮件。如果您的目标是添加(扩展)电子邮件,则API允许您在不重复自己的情况下进行添加。


在下游模块中,扩展模板

。代码块:html+jinja

{%extends'sale confirmation email/email//sale confirmation html.html%}

{%block footer%}
{{{{super()}
<;br/>;
请访问我们的<;a href="https://facebook.com/mybusiness">;facebook<;/a>;
{%endblock footer%}

mplate与
`Sale Confirmation email module<;https://github.com/openlabs/trytond Sale Confirmation email>;捆绑在一起,扩展后可添加到Facebook页面的链接。

如果您熟悉
`jinja2<;http://jinja.pocoo.org/>;``模板引擎,则此模式很常见。您可以从"jinja2 docs<;http://jinja.pocoo.org/docs/dev/templates/template inheritance>;` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `还有标题。接受参数的过滤器在
参数周围有括号,就像函数调用一样。此示例将使用逗号连接列表:
`{{list join(',')}``。

jinja文档中的"内置筛选器列表"lt;http://jinja.pocoo.org/docs/dev/templates/内置筛选器列表>;`
描述了所有内置筛选器。此外,
此模块还提供以下筛选器:

date format(date,format="medium')
+++++++++++++++++++++++++++有关其他
可能的格式,请参阅
`babel documentation<;http://babel.pocoo.org/docs/dates/date and time>;` `.


示例

代码块::html+jinja

<;td>;日期<;td>;
<;td>;{sale.date date format}<;td>;


datetimeformat(datetime,format)
+++++++++++++++++++++++有关其他
可能的格式,请参阅
`babel documentation<;http://babel.pocoo.org/docs/dates/date and time>;` `.


示例

代码块:html+jinja

有关更多格式信息,请参阅
`babel documentation<;http://babel.pocoo.org/docs/api/numbers/?highlight=format_currency babel.numbers.format_currency>;`


示例

…代码块::html+jinja

<;td>;总值<;td>;
<;td>;{sale.total_amount_currencyformat(sale.currency.code)}<;td>;



to、cc和bcc
```````````````````````````````````````
向某组收件人发送电子邮件与在电子邮件中设置
若要指示收件人,请将收件人列表发送到"to"参数。

因此,"render\u email"方法只接受"cc"参数
。要发送"bcc",可以在使用smtpserver发送电子邮件时将
同一消息发送给收件人。


示例

代码块::python

email_message=mail。呈现电子邮件(
to=['you@somewhere.com','youtoo@somewhere.com',
cc=['mydomain.com',

r/>)



发送附件
`````````````````````````

该方法还接受一个参数``attachments``它接受一个字典,其中键表示文件名,值是要附加内容的缓冲流。如果存在附件,则邮件类型将自动更改为"multipart/mixed"。附件应显示为电子邮件客户端上的可下载附件


代码块::python

er copy.pdf:订购副本,
"product photo.png":产品照片,
},


其他常见的东西
来自"email="me@mydomain.com",
to=['you@somewhere.com",
subject="一封很棒的按喇叭的电子邮件",
文本模板="我的模块/email/honking email.txt,
html_template='my_module/emails/honking email.html',



authors and contributors
----


这个模块是在"openlabs<;http://www.openlabs.co.in>;"上构建的。

专业支持
————————————————————————————————————————————————————————————————————————————————————————————————————————————/><;mailto:support@openlabs.co.in>;``团队。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaHTTP。请求侦听器   java Selenium webdriver遍历行并仅检索某些列   JavaSpring批处理在启动运行方法之前启动SimpleZoblancher运行方法   maven如何使用Maven2从javadoc生成java源代码?   java为什么我的Unicodont(Slick2D)不画画?   java取消对未使用对象的引用是否会提高冗长方法的性能?   java可执行Jar的画布比使用Eclipse Runner的小   为什么我的for循环在Android studio中与eclipse(java)产生不同的结果   java代码段字节数组到端口号   java在DynamoDB范围键中插入项   java 安卓。看法WindowManager$BadTokenException:无法添加窗口,您的活动正在运行吗?   java我想要两个列表视图同时滚动   java测试数据分离   java Saxon:每次重新部署后都需要重新启动Glassfish