Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
7 ตอบกลับ
34394 มุมมอง

Hello,

    I want to create a mail template in python as i need some dynamic values and send mail using that template. How can i create a mail.template from python side?

 

Regards,

อวตาร
ละทิ้ง

It will be good if you can explain the scenario, what exactly you want to achieve.

คำตอบที่ดีที่สุด
Hi,
You can create an email template, with the help of this blog.
Creating Email Templates in Odoo 12


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

You have to use create method of email.template object.

For e.g. if you want to create a template for sale order and want to send mail using that template than you have to write particular code inside your method

template_obj = self.pool.get('email.template')
group_model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'sale.order')])[0]
body_html = '''Message whatever you want to send'''
template_data = {
    'model_id': group_model_id,
    'name': 'Template Name',
    'subject' : 'Subject for your email',
    'body_html': body_html,
    'email_from' : '${object.user_id.email}',
    'email_to' : '${object.partner_id.email}',
}

template_id = template_obj.create(cr, uid, template_data, context=context)
template_obj.send_mail(cr, uid, template_id, ids[0], force_send=True, context=context)

It will send a mail with given values in dictionary.

Thanks.

อวตาร
ละทิ้ง

sir, I have created a email template via openerp and added a context action... it works fine... but i want my button

Button should do the same action.... send emaill i think self.pool.get('email.template').send_mail(cr, uid,9,context[1], context,True, context=context) this may do.. but givew error.. please help me..

คำตอบที่ดีที่สุด

HI,

For creating new template and sending the email using the same template from the python code, see this Videos

1. How To Create Email Template in Odoo

2. Send Email From Code Using Email Template in Odoo

Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

As far as I understood that question, you want to create a new mail, which will take some values from the current model and use that in HTML mail sent to the partner. You can easily do that, just go to the module base_calendar and look for example for _links_get function and its usage through the code.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
8
ก.ค. 24
21669
1
ก.ย. 21
3003
0
พ.ย. 20
2593
1
มี.ค. 15
6117
0
พ.ย. 19
4193