Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
17371 Lượt xem

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 :(

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

@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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả
	@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
Câu trả lời hay nhất

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)



Ảnh đại diện
Huỷ bỏ
Tác giả

Yes yopi, problem solved. Thank you anyway :)

Câu trả lời hay nhất

Thank you yobi, this helped

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Ha!

Problem solved, thank you Pawan.

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

THANK YOU

Ảnh đại diện
Huỷ bỏ