Search code examples
odooodoo-10

get email body with html format in odoo


I want to get email body from in html format,

defaults = {
        'name':  msg.get('subject') or _("No Subject"),
        'email_from': msg.get('from'),
        'email_cc': msg.get('cc'),
        'partner_id': msg.get('author_id', False),
        'description': msg.get('body'), 
    }

I want to get email body to description but when I use 'description': msg.get('body'), it takes all on text format, I want to get email body on HTML format


Solution

  • here is the basic function when creating new ticket (incoming message)

     @api.model
    def message_new(self, msg, custom_values=None):
        """ Overrides mail_thread message_new that is called by the mailgateway
            through message_process.
            This override updates the document according to the email.
        """
        # remove default author when going through the mail gateway. Indeed we
        # do not want to explicitly set user_id to False; however we do not
        # want the gateway user to be responsible if no other responsible is
        # found.
        create_context = dict(self.env.context or {})
        create_context['default_user_id'] = False
        defaults = {
            'name':  msg.get('subject') or _("No Subject"),
            'email_from': msg.get('from'),
            'email_cc': msg.get('cc'),
            'partner_id': msg.get('author_id', False),
        }
        if custom_values:
            defaults.update(custom_values)
    
        res_id = super(ProjectIssue, self.with_context(create_context)).message_new(msg, custom_values=defaults)
        issue = self.browse(res_id)
        email_list = issue.email_split(msg)
        partner_ids = filter(None, issue._find_partner_from_emails(email_list))
        issue.message_subscribe(partner_ids)
        return res_id
    

    when I add

    'description' : msg.get('body'),
    

    I can get the body of the email, but its on text format, then I check on 'description' and I found this

    description = fields.text('Private Note')
    

    that's why I only get text format, not HTML format, so I change the description format to this

    description = fields.Html('Private Note')
    

    then the format of description is back to normal and readable.