Odoo Help


send email via new API with additional data

on 4/20/16, 7:38 AM 790 views


Follow is my code to send email:


def mailmessage(self):

vals ={}

domain = [('name','like','EAR Activation Request')]

template = self.env['email.template'].search(domain, limit=1)

template = template[0]


template.send_mail(self.id, True)

return True

My template is getting all the data correctly from model. However, I need to pass a dynamic data to the template before sending email. Be it email_to or ip_address. Can someone guide me how can I pass these two variables on runtime in my python code before send_mail function so the template pick them? 


Prakash Sharma
On 4/20/16, 9:03 AM

Hi  Alex  below i am posting the  code for  new  and simple way  for doing this task

 please use self.env.ref instead of self.env['email.template'].search(domain, limit=1)

mytemplate_obj = self.env.ref('my_module.my_mail_template', False)

here the mytemplate_obj is the object of  email.template    , it's mean it's a active record .

Now You can change/set the field value (email_from,subject,email_to)of  this object simply  and call the send_mail.

Hope this may help you.

On 4/20/16, 9:36 AM

Prakash, I am able to set email_to. thanks

However, I am unable to set any value for ${object.ip_address}

Can you tell me how can I set it?

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: 4/20/16, 7:38 AM
Seen: 790 times
Last updated: 4/20/16, 12:29 PM