Skip to main content

Create Email Template and Send Email Programmatically in Odoo 1x

Odoo has a powerful email sending module that allows you to create and send emails programmatically. In this blog post, we will show you how to create an email template and send it using the Odoo email sending module.

Create Email Template

<?xml version="1.0" encoding="utf-8"?>
    <data noupdate="1">
        <!--Email template -->
        <record id="my_email_template" model="mail.template">
            <field name="name">First Email Template</field>
            <field name="email_from">${ and or ''}</field>
            <field name="subject">New Feedback from ${}</field>
            <field name="model_id" ref="my_module.model_custom_model"/>
            <field name="auto_delete" eval="True"/>            
            <field name="lang">${object.address_home_id.lang}</field>
            <field name="body_html"><![CDATA[

   Dear ${(}, <br/><br/>
   There is a new feedback on your website. You can read it here.


Send Email Programmatically

class MyModel(models.Model):
    _name = 'my.model'
    _description = 'My Model'

    def send_email(self):
        body_html = 'Hi {},<br/><br/>'.format(someone_name)        
        body_html += '<div>The body goes here</div>'

        email_values = {
            'email_to': '[email protected]',
            'email_from': '[email protected]',
            'body_html': body_html,
        template_id = self.env['mail.template'].search([('model', '=', 'custom.model')], limit=1)
        template_id.send_mail(, force_send=True, email_values=email_values)

By continuing to use the site, you agree to the use of cookies.