Search Here

On Button Click Send Email From Code using Template

Most of the time we need to send an email after successfully completion of some tasks or event. To day I will show you how to send an email in Odoo using button click.

Send Email From Code using Template on Button Click in Odoo

Send Email in Odoo From Code

To send an email in Odoo first of all we need create email template. We can create this email template using following two ways.

  1. By using Email Template Menu Interface
  2. By using xml (code)

By using Odoo interface firstly we create a email template by clicking on “Create” button and fill the form.

Send Email From Code using Template on Button Click in Odoo


Here our focus is to create email template using xml. Follow these steps to create email template through code.

Read More: How to display confirmation display box / message box on button click 
  1. Create new xml file in your module
  2. Copy below code and past in your newly created xml file
  3. Register your newly created xml file in openerp.py

Create Email Template



Now its time to write button method/function to send an email. Follow these steps to create a button and its event/function. 


Create a button and handle button method in models.py file

<button string="Send Email" type="object" name="btn_send_email " confirm="Are you sure you want to Send email to students?" />

Send Email From Code using Template





Post a Comment

8 Comments

  1. Hello
    so how to Handle button method in models.py file?
    now it return this error
    AttributeError: 'res.letter' object has no attribute 'btn_send_email

    ReplyDelete
  2. Hey,
    You must create button code "btn_send_email" in XML of your "res.letter" model.

    ReplyDelete
  3. can we write btn_send_email instead of proposal_title_approved function?

    If I didn't have an attribute name btn_send_email.

    and It didn't work yet. How it will work please let me know.

    ReplyDelete
  4. Good mornning. Please I get this error when using the above xml file. Can some one help me solve this ?
    ParseError: "External ID not found in the system: sunu__stock.model_postgraduate_thesis"

    ReplyDelete
    Replies
    1. sunu__stock.model_postgraduate_thesis

      In above line you just need to change your model name like " sunu__stock.model_your_model_goes_here"

      Delete
  5. Hello I'm stuck on configuring mail too with v11, can someone assist me ?

    ReplyDelete
  6. It can send real mail? Use as recipient email definite in @api? Thanks

    ReplyDelete