diff --git a/mail_tracking/models/ir_mail_server.py b/mail_tracking/models/ir_mail_server.py
index e364a570..067c4029 100644
--- a/mail_tracking/models/ir_mail_server.py
+++ b/mail_tracking/models/ir_mail_server.py
@@ -23,7 +23,7 @@ class IrMailServer(models.Model):
tracking_email_id = False
# https://regex101.com/r/lW4cB1/2
match = re.search(
- r']* data-odoo-tracking-email=["\']([0-9]*)["\']', body)
+ r']*data-odoo-tracking-email=["\']([0-9]*)["\']', body)
if match:
try:
tracking_email_id = int(match.group(1))
diff --git a/mail_tracking/models/mail_tracking_email.py b/mail_tracking/models/mail_tracking_email.py
index 21c3728b..eb3c9d92 100644
--- a/mail_tracking/models/mail_tracking_email.py
+++ b/mail_tracking/models/mail_tracking_email.py
@@ -222,8 +222,12 @@ class MailTrackingEmail(models.Model):
self.ensure_one()
tracking_url = self._get_mail_tracking_img()
if tracking_url:
+ content = email.get('body', '')
+ content = re.sub(
+ r']*data-odoo-tracking-email=["\'][0-9]*["\'][^>]*>',
+ '', content)
body = tools.append_content_to_html(
- email.get('body', ''), tracking_url, plaintext=False,
+ content, tracking_url, plaintext=False,
container_tag='div')
email['body'] = body
return email