Enable Dark Mode!
By: Ijaz Ahammed

How to Create Email Templates in Odoo 14

Technical Odoo 14

Emails are essential to every business as they give information about the business operations carried out to everyone. It acts as a communication channel between businesses and customers.

Here the email template is created by using XML, Jinja2, python in odoo 14.

In odoo ERP it is possible and easy to customize Emails. The latest version, Odoo 14 also comes with a vast option that needed businesses to adopt. 

So here we are doing how email templates can be created in odoo14.

The dependency for this is

'depends': ['mail','contacts']

The next step is to create a new XML record as given below-

1. id

The generated record's `external id`

2. model (mandatory)

The email template model is the same for all because of the default email functions in odoo.

3. name (mandatory)

It is for easy identification emails mnemonic/description is given.

4. ref (mandatory)

The values needed from a model that needs to send.

5. email_from

Used for identifying who is sending the email.

6. email_to(mandatory)

The recipient’s email address is given here.

7. report_template

The attachments like pdf or others are mentioned here.

8. subject

It is for giving the subject of the email, as it is an important part of the email.

9. body_html

The content of the email is described herewith by using jinja2.

<record id="email_template" model="mail.template">
<field name="name">EMAIL TEMPLATE NAME</field>
<field name="model_id"ref="module_name.model_sample.mail">
<field name="auto_delete" eval="True"/>
<field name="email_from">${(object.res_user_id.email}</field>
<field name="email_to">${object.client_name.email}</field>
<field name="report_template" ref="action_example_pdf"/>
<field name="subject">${object.amc}</field><field name="body_html">
<![CDATA[<p>Dear ${(object.client_name.name)},
Good job, this is our first e-mail template!<br/> </p>Regards,<br/> ${(object.company_id.name)} ]]></field> </record> /data> </odoo>

Odoo Email templates come with jinja2 by default. By using this we can value from a record and use it for Email automatically.


<field name="subject">${object.amc}</field>

Now we need to create a python function as below for calling the email and passing the values to it. 

@api.multidef action_send_email(self):
self.ensure_one()ir_model_data = self.env['ir.model.data']
template_id = ir_model_data.get_object_reference('module_name',   'template_name')[1]
except ValueError:template_id = Falsetry:compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose
except ValueError:
compose_form_id = False ctx = { 'default_model': 'exmaple.email', 'default_res_id': self.ids[0], 'default_use_template': bool(template_id), 'default_template_id': template_id, 'default_composition_mode': 'comment', 'mark_so_as_sent': True, 'force_email': True } return { 'type': 'ir.actions.act_window', 'View_type': 'form', 'view_mode': 'form', 'res_model': 'mail.compose.message', 'views': [(compose_form_id, 'form')], 'view_id': compose_form_id, 'target': 'new', 'context': ctx, }
Odoo 14 Development Tutorials Odoo TrainingOdoo 14 - Email Marketing

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message