Skip to Content
Menu
This question has been flagged
2 Replies
4493 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

Avatar
Discard
Best Answer

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.


Avatar
Discard
Author Best Answer

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?

Avatar
Discard