Enable Dark Mode!
By: Alakananda P

Creating E-mail Templates in Odoo 15

Technical Odoo 15 Marketing

Email is an important way of business communication between businesses and customers. Using email can significantly benefit businesses as it provides efficient and effective ways to transfer all types of electronic data. 
This email template blog describes you creating email templates using XML, Jinja2, python in Odoo 15.
In Odoo 15 ERP, it is possible to customize Email Templates fast and easily. Odoo 15 also provides solutions vast options for business operations to adapt. 
So here we are defining how to make a new email template in Odoo15.
Step1: Give dependencies,
'depends' : ['mail','contacts']
Create a new XML record,
1. Id
It finds the generated `external id` for the records.
2. model (mandatory)
Email functions have default functions in the Odoo platform. So All email template models are the same. 
3. name (mandatory)
It will quickly identify emails mnemonic/description is given. Which is also shown,
Goto Settings > Technical > Email > Templates.
4. ref (mandatory)
Ref returns values or corresponding records from the XML id or model that must be sent.
5. auto_delete
If it is set to true, an email will be permanently deleted after sending it.
If it is false, an email will be kept after sending it.
6. Email_fr They are used for identifying the sent email from which email.
7. email_to(mandatory)
This will contain the recipient’s email address
8. report_template
If you have to send any attachments like pdf or others, you can mention the report template id.
9. subject
It will contain the email's subject, as it is essential in email. User to get the title of the email after sending.
10. body_html
Inside the body_html contains the design and content of the e-mail. After sending the email, you can also edit the style and template and pre-fill data because the contents of email templates are given by using jinja2.
       <record id="email_template_name" model="mail.template">
           <field name="name">EMAIL TEMPLATE NAME</field>
           <field name="model_id" ref="module_name.model_sample_name"/>
           <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">
                   Dear<t t-out="object.client_name.name"/>,
                   Good job, this is our first e-mail template!
               <t t-out="object.company_id.name"/>
Odoo Email templates are developed with jinja2 by default. It can access record value and automatically fill it in email.
For Example;
<field name="subject">{{object.amc}}</field>
Create a python function as below. It defines a part and passes the values to it. 
def action_send_email(self):
   ir_model_data = self.env['ir.model.data']
       template_id =    ir_model_data._xmlid_lookup('module_name.template_name')[2]
  except ValueError:
   template_id = False
   compose_form_id = ir_model_data._xmlid_lookup('mail.email_compose_message_wizard_form')[2]
except ValueError:
   compose_form_id = False
   template_id = self.env.ref('event.event_registration_mail_template_badge')
   compose_form = self.env.ref('mail.email_compose_message_wizard_form')
   ctx = {
       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,
Lets now move on to understand the differences between email templates in the Odoo 15 and its previous version the Odoo 14.
Difference Between Email Templates in Odoo 14 and Odoo 15.
This qweb plugin includes:
 Make dynamic variables (eg. <t t-out="variable"/>) not editable (for preventing the user to shoot himself in the foot)
Exist - Your order <strong>${object.name}</strong>
Replace - Your order <strong t-out="object.name or ''"/>
We still want users to use dynamic variables for char fields (e.g. subject, from, to, etc...). We made a new rendering engine called "inline_template" that will render an expression enclosed by `{{` and `}}.`
Exist - <field name="email_to">${object.email_formatted | safe}</field>
Replace - <field name="email_to">{{object.email_formatted | safe}}</field>
- Group and hide related logical branching (ie. t-if, t-elif and t-else) in order to see only one at once
Exist - % for line in object.order_line:
   % if not line.is_delivery and line.display_type in ['line_section', 'line_note']:
Replace - <t t-foreach="object.order_line" t-as="line">
   <t t-if="(not hasattr(line, 'is_delivery') or not line.is_delivery) and line.display_type in ['line_section', 'line_note']">
- A floating select input to switch visibility of a particular logical branching
style t-tags to make them stand out
These are ceratin on of the difference in the email temples between the Odoo 15 and Odoo 14.

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



Shouldn't there be type="html" after name="body_html"? It gives me error without it.





in mail template we provide the email_to as object.client_email, ok . what's the object , ? . we provide a model ,is that model or other model




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