This question has been flagged
1 Reply
1871 Views

I want to send a file from odoo to my personal email(for testing).

And I'm using this code ,which runs fine:

tools.email_send(email_from='sending@test.fr',
    email_to=['recive@gmail.com'],
    subject='Some subject',
    body='hello')

So I recive 'hello' and there is not problem of connection.

But it's impossible to attache a file to this method.

Here is my file, and I don't know how to send it with my message:

att_id = self.env['ir.attachment'].create({

'name': 'My name',
'type': 'binary',
'datas':excel_file,
'datas_fname': 'Myname.xsl',
'res_model': 'print.invoice..cron',
'res_id': self.id,
'mimetype': 'text/csv'
}) 

att_id contains the id of attachment

Avatar
Discard
Best Answer

Hi,

You can try this code based on the template

template = self.env.ref(
'module name.template_name')
attachment = self.env['ir.attachment'].create({
'name': '{name
'type': 'binary',
'datas': data_encoded,
'store_fname': data_encoded,
'mimetype': 'application/pdf',
'res_model': 'model_name',
'res_id': self.id
})
template.send_mail(self.id, force_send=True,
email_values={
'email_to': person ,
'attachment_ids': attachment.ids
})

Regards

Avatar
Discard