Odoo Help

Welcome!

This community 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.

0

send email via new API with additional data

By
Alex
on 4/20/16, 7:38 AM 365 views

Hi,

Follow is my code to send email:

    @api.multi

def mailmessage(self):

vals ={}

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

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

template = template[0]

print(template.email_to)

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? 


Thanks

2

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

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.


0
Alex
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?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/20/16, 7:38 AM
Seen: 365 times
Last updated: 4/20/16, 12:29 PM