Skip to Content
Menu
This question has been flagged
4 Replies
17083 Views

In old API everything works, if I'm trying to adapt code to the new API .... failed, can anyone give me an example of working new API sendmail code please ?

After conversion, I've met some problems but finally solved, however, still no positive result,  not sending messages.

@api.model

def mailmessage(self):

    vals = {}

    domain=[('name','ilike','Processing_order')]

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

    for temp in tplate:

        template = temp.id

        if template:

            print 'Sending e-mail using template "'+temp.name+'" ..... ' # message is displayed

            self.env['email.template'].send_mail(temp.id)

            print '..... mail sent.' # message is displayed

            return True

        else:

            return

but inbox .... still empty :(

No sending emails :(

Avatar
Discard
Best Answer

@api.multi

def mailmessage(self):

vals = {}

domain=[('name','like','Order_processing')]

template = self.env['email.template'].search(domain, limit=1) # in new api you will get list of objects instead of list of integers from search()

if not template:

return

template = template[0]

if template.email_to:

template.send_mail()

 return True

Avatar
Discard
Author

Finally, I got no errors but also got no email in my inbox :)

Author
	@api.model
	def mailmessage(self):
		vals = {}
		domain=[('name','ilike','Processing_order')]
		tplate = self.env['email.template'].search(domain, limit = 1)
		for temp in tplate:
			print 'Template', temp.name
			template = temp.id
		if template:
			print 'Sending e-mail using template "',temp.name,'" ..... '
			self.env['email.template'].send_mail(template, True)
			print '.... mail sent.'
			return True
		else:
			return
Best Answer

Hi Dr Obx,

Did you solved it?

Try this:


@api.multi

def mailmessage(self):

    template_id = self .env.ref('module_name.xml_id') # xml id of your email template

    # force_send=True: tells odoo to send the email directly

    # force_send=False: odoo will put it in queue (default)

    template_id.send_mail(self.ids, force_send=True)



Avatar
Discard
Author

Yes yopi, problem solved. Thank you anyway :)

Best Answer

Thank you yobi, this helped

Avatar
Discard
Author Best Answer

Ha!

Problem solved, thank you Pawan.

Unfortunately I can't give you more 'Up Vote'

THANK YOU

Avatar
Discard