如何在以下功能中使用电子邮件模板? [英] how can I use a email template in the following function?
本文介绍了如何在以下功能中使用电子邮件模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def button_confirm_mom(self,cr,uid,id, context = None)
sobj = self.browse(cr,uid,ids)
msg_pool = self.pool.get('mail.mail')
cc_text =''
msg_vals = {
'subject':MoM已创建,
'email_from':abc@gmail.com,
'reply_to':False,
'state':'outgoing',
'model':False,
'res_id':False,
'auto_delete':False,
}
如果sobj.matp:
在sobj.matp中的cc_obj:
如果cc_obj.empname.work_email:
cc_text + = cc_obj.empname.work_email +', '
如果sobj.newa:
为cc_obj 1 in sobj.newa:
if cc_obj1.empname.work_email:
cc_text + = cc_obj1.empname.work_email +','
msg_vals ['email_cc'] = cc_text
self .pool.get('mail.mail')。create(cr,uid,msg_vals)
return True
我想知道如何使用模板并发送邮件给多个人。任何人都有这个想法吗?
解决方案
你可以这样使用。添加新的邮件模板(如xml文件)。示例:
<?xml version =1.0?>
< openerp>
< data noupdate =1>
< record id =event_YOUR_ID_mail_templatemodel =mail.template>
< field name =name>模板名称< / field>
<! - 例如model-res.users - >
< field name =model_idref =your_module.model_res_users/>
< field name =email_from> test@gmail.com< / field>
< field name =email_to> $ {object.email | safe}< / field>
< field name =lang>< / field>
< field name =subject>您的主题< / field>
< field name =auto_deleteeval =True/>
< field name =body_html><![CDATA [邮件的邮件] < p>您可以在这里使用$ {object.name}或对象的任何字段< / p> ]>< /场>
< / record>
< / data>
< / openerp>
安装完成后,您可以在此处找到(和编辑)模板:顶部菜单)设置 - >(左侧菜单)电子邮件 - >模板(您必须使用开发人员模式才能看到此菜单项)。
如何在python代码中使用此模板:
temp = self.env.ref('your_module.event_YOUR_ID_mail_template' )
如果temp:
#示例:用户 - res.users的实例
temp.sudo()。with_context()。send_mail(user.id,force_send = True)
I am trying to send mail function using the following code:
def button_confirm_mom(self,cr,uid,ids,context=None):
sobj = self.browse(cr, uid, ids)
msg_pool = self.pool.get('mail.mail')
cc_text = ''
msg_vals = {
'subject' : "MoM has been created",
'email_from' : "abc@gmail.com",
'reply_to' : False,
'state' : 'outgoing',
'model' : False,
'res_id' : False,
'auto_delete' : False,
}
if sobj.matp:
for cc_obj in sobj.matp:
if cc_obj.empname.work_email:
cc_text += cc_obj.empname.work_email + ','
if sobj.newa:
for cc_obj1 in sobj.newa:
if cc_obj1.empname.work_email:
cc_text += cc_obj1.empname.work_email + ','
msg_vals['email_cc'] = cc_text
self.pool.get('mail.mail').create(cr,uid,msg_vals)
return True
I wanted to know how i can use a template and send the mail for multiple people. Anyone has any idea on this ?
解决方案
You can use this way. Add new template for mail(like view xml-file). Example:
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<record id="event_YOUR_ID_mail_template" model="mail.template">
<field name="name">Name of template</field>
<!-- for example model - res.users -->
<field name="model_id" ref="your_module.model_res_users"/>
<field name="email_from">test@gmail.com</field>
<field name="email_to" >${object.email|safe}</field>
<field name="lang"></field>
<field name="subject">Your subject</field>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[Message of mail. <p>You can use here ${object.name} or any fields of object,</p> ]]></field>
</record>
</data>
</openerp>
After installing\updating your module you can find(and edit) template here: (top menu)Settings -> (left menu) email -> template(you must use developer mode to see this menu item).
How we can use this template in python code:
temp = self.env.ref('your_module.event_YOUR_ID_mail_template')
if temp:
# example: user - instance of res.users
temp.sudo().with_context().send_mail(user.id, force_send=True)
这篇关于如何在以下功能中使用电子邮件模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文