0

hello i have a method send an email but i want to send a file how to do that

   class a(models.Model):
_inherit = 'b'

upload_file = fields.Binary(string="Upload File")
file_name = fields.Char(string="File Name")

@api.multi
def send_email(self):

    contenu_bcc=""
    template_obj = self.env['mail.mail']
    for mail in self.customer.email:
        contenu_bcc=str(contenu_bcc)+"," +str(customer.email)

    template_data = {
        'subject': 'subject  : ',
        'body_html': 'body',
        'email_from': 'admin',
        'email_to': test,#admin
        'attachment_ids': .... 


    }
    template_id = template_obj.create(template_data)
    template_obj.send(template_id)

the email works fine but i want to add a file to email how to do that

NB : the file is a field on object B

Caludio
  • 135
  • 11

1 Answers1

0

You have to create an ir.attachment record with your file. Then, get the ID of the new ir.attachment recrod and put it on the 'attachment_ids' value of your template_data dict.

Quentin THEURET
  • 1,222
  • 6
  • 12