Odoo Help


How to send an email via python with the new API ?

on 5/29/15, 8:58 AM 2,762 views


I'm trying to create a function to send an email but I can't find anywhere how to do it with the new API.

I created the template that should be sent already.


def action_email(self):

     if not self.customer:

         raise except_orm("...", ...")

    customer_email = self.customer.email

     if not customer_email or len(customer_email.strip()) <= 0:

         raise except_orm("...", ...")



On 5/30/15, 1:10 PM

You inherit model mail.thread in your model

 _inherit = ['mail.thread'] 

and create mail by way like this (example from account_invoice.py)

def action_invoice_sent(self):
""" Open a window to compose an email, with the edi invoice template
message loaded by default
assert len(self) == 1, 'This option should only be used for a single id at a time.'
template = self.env.ref('account.email_template_edi_invoice', False)
compose_form = self.env.ref('mail.email_compose_message_wizard_form', False)
ctx = dict(
return {
'name': _('Compose Email'),
'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,

In my case I had to remove "default_template_id=template.id," on Odoo 9? Should this be a external id?

Lucas Huber
on 3/15/16, 12:15 PM

Thanks! Your answer got me out of a bind.

Thinkwell Designs, Dave Burkholder
on 7/20/16, 9:49 PM
Lucas Huber
On 3/15/16, 12:45 PM

It seems the model name email.template has changed to mail template in Odoo 9:

<!-- email_template for meetings -->
 <data noupdate="1">
 <record id="email_template_scrum_meeting" model="mail.template">
 <field name="name">Email Template for Meeting</field>
 <field name="email_from">${object.user_id_meeting or ''}</field>
 <field name="subject"> ${object.name or ''}</field>
 <field name="model_id" ref="project_scrum.model_project_scrum_meeting"/>
 <field name="auto_delete" eval="True"/>
 <field name="email_to">${object.user_id_meeting or ''}</field>
 <field name="body_html">
 <div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif;
 font-size: 16px; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); ">
 <p><p>Date: ${object.start_datetime}</p> <br/>
 <p> ${object.agenda}</p>

There are some old template with model="email.template" around in the forum.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/29/15, 8:58 AM
Seen: 2762 times
Last updated: 3/15/16, 12:45 PM