Anudocs
Anudocs

Reputation: 686

Odoo 10 : Sending Email from odoo

I inherited the contacts module and writing a sendEmail function :

def sendEmail(self,values):
            _logger.error("sendEmail Called")
            mail_pool = self.env['mail.mail']
            values={}

            values.update({'subject': 'Catastrophe in Odoo'})

            values.update({'email_to': '[email protected]'})

            values.update({'body_html': 'something is wrong' })

            values.update({'body': 'someone is messing up' })     

            msg_id = mail_pool.create(values)
            _logger.error(str(msg_id))

            if msg_id:

                 result= mail_pool.send([msg_id]) 
                 _logger.error(str(result)) 

which produces this log :

2018-10-01 15:17:20,144 21332 ERROR test odoo.addons.contacts.models.models: sendEmail Called
2018-10-01 15:17:20,165 21332 ERROR test odoo.addons.contacts.models.models: mail.mail(13,)
2018-10-01 15:17:20,165 21332 ERROR test odoo.addons.contacts.models.models: True

I also added mail in my manifest file :

 'depends': ['mail','base', 'contacts', 'web_readonly_bypass'],

After all these , I dont get email in my account.My outgoing server is also correctly configured because I am able to send reset password email to the users. So am i missing something in the code?

Upvotes: 0

Views: 1870

Answers (2)

Jesus Velazquez
Jesus Velazquez

Reputation: 61

This is my example based on your first exameple and it's working for me:

def send_assessment(self):
  mail_pool = self.env['mail.mail']
  values={}
  values.update({'subject': 'Catastrophe in Odoo'})
  values.update({'email_to': '[email protected]'})
  values.update({'body_html': 'something is wrong' })
  values.update({'body': 'someone is messing up' })
  msg_id = mail_pool.create(values)
  result =  msg_id.send()

Upvotes: 0

aekis.dev
aekis.dev

Reputation: 2754

I think that your issue is that you aren't calling properly the send method with the created record. Try like this and it should work

result= msg_id.send()

The idea is to call the method send on the recordset msg_id as states in the new api usage.

Upvotes: 1

Related Questions