Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
17360 Vistas

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
Descartar
Mejor respuesta

@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
Descartar
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
Mejor respuesta

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

Yes yopi, problem solved. Thank you anyway :)

Mejor respuesta

Thank you yobi, this helped

Avatar
Descartar
Autor Mejor respuesta

Ha!

Problem solved, thank you Pawan.

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

THANK YOU

Avatar
Descartar