How to integrate EmailTemplate in Odoo
Odoo already has its own mail.template, but if you want to design in the EmailTemplate visual editor and version the HTML, you can render from the API and use the result in mail.mail or a delivery connector. This guide shows a urllib-based model, sending from sale.order, and a controller to receive webhooks.
How do I render and send email templates from Odoo?
-
Prepare the API key in Odoo
Store the key in system parameters (ir.config_parameter) or in a server environment variable. Never in the module code.
bash# Settings > Technical > System Parameters # emailtemplate.api_key = et_your_key # emailtemplate.api_url = https://api.emailtemplate.theboomer.dev/api/v1 # emailtemplate.order_template = 64f8a1b2c3d4e5f6a7b8c9d1 -
Model that renders the template
A transient model or a mixin with the HTTP client. Odoo 16/17/18 usually ships requests as a dependency; if not, use urllib.
python# models/email_template.py import json import urllib.request from odoo import models, fields, api class EmailTemplateMixin(models.AbstractModel): _name = 'email.template.mixin' _description = 'EmailTemplate render' def _render(self, template_id: str, variables: dict) -> dict: url = self.env['ir.config_parameter'].sudo().get_param('emailtemplate.api_url') key = self.env['ir.config_parameter'].sudo().get_param('emailtemplate.api_key') payload = json.dumps({'variables': variables}).encode() req = urllib.request.Request( url + '/templates/' + template_id + '/render', data=payload, headers={'Content-Type': 'application/json', 'x-api-key': key}, method='POST', ) with urllib.request.urlopen(req, timeout=10) as res: return json.loads(res.read().decode()) -
Send the email from sale.order
Render with order data and create the mail.mail with the resolved HTML. Odoo’s mail server performs the delivery.
python# models/sale_order.py from odoo import models class SaleOrder(models.Model): _inherit = 'sale.order' def send_confirmation(self): self.ensure_one() data = self.env['email.template.mixin']._render( self.env['ir.config_parameter'].sudo().get_param('emailtemplate.order_template'), { 'user.name': self.partner_id.name, 'order.id': self.name, 'order.total': str(self.amount_total), }, ) mail = self.env['mail.mail'].sudo().create({ 'subject': data['subject'], 'body_html': data['html'], 'email_to': self.partner_id.email, }) mail.send() return mail -
Receive EmailTemplate webhooks
A public controller verifies the HMAC signature and updates local state. Useful to know when a template changed.
python# controllers/webhook.py import hmac import hashlib import json from odoo import http from odoo.http import request class EmailTemplateWebhook(http.Controller): @http.route('/emailtemplate/webhook', type='json', auth='none', methods=['POST'], csrf=False) def receive(self, **kw): secret = request.env['ir.config_parameter'].sudo().get_param('emailtemplate.webhook_secret') body = request.httprequest.get_data() signature = request.httprequest.headers.get('X-Signature', '') expected = hmac.new(secret.encode(), body, hashlib.sha256).hexdigest() if not hmac.compare_digest(signature, expected): return {'error': 'invalid signature'} payload = json.loads(body) request.env['email.template.log'].sudo().create({'event': payload.get('event'), 'payload': json.dumps(payload)}) return {'ok': True} -
Alternative: Odoo mail.template
If you do not need git-style versioning, the native mail.template with QWeb and object. is enough. EmailTemplate provides the visual editor and multi-provider export.
xml<!-- QWeb template instead of EmailTemplate HTML --> <div> <p>Hi <t t-esc="object.partner_id.name"/>,</p> <p>Your order <t t-esc="object.name"/> is on its way.</p> </div>
| Item | Free | Pro | Team | Enterprise |
|---|---|---|---|---|
| Monthly price (EUR, VAT excluded) | €0 | €19 | €59 | €149 |
| Renders per month | 500 | 25,000 | 100,000 | 500,000 |
| Concurrent templates | 3 | 25 | Unlimited | Unlimited |
| Users | 1 | 2 | 10 | 25 |
| AI credits per month | 50 | 500 | 2,000 | 10,000 |
| AI operation cost | generate: 10 credits · suggest: 5 credits. Charged to the credit wallet (they do not consume renders) and the same on every plan. Packs: 500 credits / €9, 2,000 / €29, 5,000 / €69, 10,000 / €119. | |||
| Stack provider export | Render returns HTML (text/html) for mail.mail or mail.template. Per provider: format=klaviyo returns Liquid HTML, format=mailchimp returns JSON and format=resend returns JSX. | |||
Subscription prices in USD/month; credit packs are charged in EUR. Product-published data, not estimates.
Frequently asked questions
Does it work on Odoo 16, 17 and 18?
Yes. The example uses urllib and standard models (ir.config_parameter, mail.mail, http.Controller), present in all three versions.
Native mail.template or EmailTemplate?
mail.template with QWeb is enough for simple cases. EmailTemplate adds a drag-and-drop visual editor, git-style versioning and export to Klaviyo, Mailchimp and Resend.
How do I test without sending real emails?
Set the outgoing mail server to test mode or use the dashboard preview: the render returns the HTML without delivering the message.