How to create program for sending mail automatically from openerp using python

前端 未结 2 2159
灰色年华
灰色年华 2021-02-09 07:00

How to create program for sending mail automatically from openerp using python?

I have created openerp module. I am trying to send mail to a client, when client id is ge

2条回答
  •  情歌与酒
    2021-02-09 07:43

    If you want to send an HTML email, the only way I have found is to send an email template via a server action.

    Once you have the template created, discover it's template id by viewing the template and seeing what the id parameter is in the URL.

    Then create a new server action, set the object to match the template and set the type to python code. Insert the following code:

    self.pool.get('email.template').send_mail(
        cr, uid, , context['active_id'],True, context=context)
    

    Replacing with the appropriate template id.

    Just explaining some of the other fields

    • context['active_id'] gives the current id of the lead/invoice/etc being used to create the template with
    • The 5th value True forces the email to be sent immediately rather than adding it to the queue. It would be better to leave as False but due to a bug in version 7, it can lose email addresses when being added to the queue.

    You can look in addons/email_template/email_template.py and search for the send_mail function for further information.

提交回复
热议问题