Outgoing Email Configuration

As an example, we are going to send an email to Sales Person when his/her Sales Order is confirmed.

1) Create an email template,

In this case, we create new method that do the sending called send_mail_confirm_order_to_sale(). We want to inherit this new method tosale_order.confirm_send_note() method.

class sale_order(osv.osv):

    _inherit = 'sale.order'

    def send_mail_confirm_order_to_sale(self, cr, uid, ids, context=None):
        if not context:
            context = {}
        # Send email with template
        template = self.pool.get('ir.model.data').get_object(cr, uid, 'ext_sale_mail', 'confirm_order_to_sale')
        for order in self.browse(cr, uid, ids, context):
            if order.user_id and order.user_id.email:
                self.pool.get('email.template').send_mail(cr, uid, template.id, order.id, False, context=context)
        return True

    def confirm_send_note(self, cr, uid, ids, context=None):
        super(sale_order,self).confirm_send_note(cr, uid, ids, context=context)
        # Also send email to sales person
        self.send_mail_confirm_order_to_sale(cr, uid, ids, context=context)


Please note that the exact method is,

self.pool.get('email.template').send_mail(cr, uid, <template.id>, <resource.id>, <force send>, context=context)


If <force send> = True, system will send it right away (slower). Else False, it will send to the queue first.

  • Check the email queue in menu > Settings > Email > Emails. User can see the status as well as force to send here.
  • Queued email will be sent by Scheduled Actions –> Email Queue Manager

2) Create template,

<?xml version="1.0" encoding="UTF-8"?>
    <data noupdate="1">
        <!-- Email template for Confirm Order to Sales Person -->
        <record id="confirm_order_to_sale" model="email.template">
            <field name="name">Confirm Order to Sales Person</field>
            <field name="model_id" ref="sale.model_sale_order"/>
            <field name="email_from"><![CDATA[No-Reply <noreply@localhost>]]></field>
            <field name="email_to">${object.user_id and object.user_id.email or ''}</field>
            <field name="subject">Your order ${object.name or ''} is confirmed!</field>
            <field name="body_html"><![CDATA[
<p>Your order <b>${object.name or ''}</b> is already confimed.</p>

<p>Folloing are some details of your order,</p>

<b>Customer:</b> ${object.partner_id and object.partner_id.name or ''}<br>
<b>Date:</b> ${object.date_order or ''}<br>
<b>Amount:</b> ${object.amount_total or ''}<br>
<b>Sales person:</b> ${object.user_id and object.user_id.name or ''}