如何通过代码为多个用户(CC)发送邮件?

时间:2015-12-18 06:59:11

标签: email openerp odoo-8 openerp-8

这是我目前为一个人尝试的代码

def send_mail_employee(self,cr,uid,ids,context=None):
        record_obj = self.browse(cr,uid,ids,context=context)
        ir_model_data = self.pool.get('ir.model.data')
        template_obj = self.pool.get('email.template')
        attch_ids = []
        for rec in record_obj:
            if not rec.name.work_email:
                raise osv.except_osv(_('Warning!'), _('Please configure employee email address!'))
            else:
                for attch in rec.attchment_lines:
                    attch_ids.append(attch.id)
                template_id = ir_model_data.get_object_reference(cr,uid,'registers', 'email_template_register_courier')[1]
self.pool.get('email.template').write(cr,uid,template_id,{'body_html' : rec.email_body,'subject' : rec.subject,'attachment_ids':[(6,0,attch_ids)]})
self.pool.get('email.template').send_mail(cr,uid,template_id,rec.id,force_send=True,context=context)
                raise osv.except_osv(_('Success'), _('Mail has been sent successfully'))

        return True 

,模板就像这样

<openerp>
    <data>
        <!--Email template for Register Courier-->
         <record id="email_template_register_courier" model="email.template">
            <field name="name">Notification for Courier</field>
            <field name="email_from">${object.name.work_email}</field>
            <field name="subject">Notification for Courier</field>
            <field name="email_to">${object.name.work_email}</field>
        <field name="email_cc">${object.cc.work_email}</field>
            <field name="model_id" ref="model_registers_courierin"/>
            <field name="auto_delete" eval="True"/>
            <field name="body_html"><![CDATA[<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
                <p>Hello ${object.name.name},</p>
                <p>This email is to inform you that your courier received</p>
              <P>Thank you</p>
           </div>
    ]]>
          </field>
        </record>

</data>
</openerp> 

现在我创建了一个one2many字段,就像名为'ref_cc'的树视图一样,我希望通过代码将整个记录发送到电子邮件cc中的人员列表。任何想法都会非常有用。 Email CC

0 个答案:

没有答案