Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4 Antworten
17363 Ansichten

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
Verwerfen
Beste Antwort

@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
Verwerfen
Autor

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

Autor
	@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
Beste Antwort

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
Verwerfen
Autor

Yes yopi, problem solved. Thank you anyway :)

Beste Antwort

Thank you yobi, this helped

Avatar
Verwerfen
Autor Beste Antwort

Ha!

Problem solved, thank you Pawan.

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

THANK YOU

Avatar
Verwerfen