I'm trying to send .html content as mail body using Python, everything works except the internal links present in the html file. Internal links are working as expected when I open the file in browser, but in the mail body those links were not navigating to corresponding headers (like Table of contents). I'm using MIMEText() to parse the html content by UTF-8 (I'm not sure this could be the issue)
I've tried to replicate outlook internal page linking using a macro, but it didn't work for this usecase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart()
report_file = open('C:\\Users\\thiru\\python_test_engine\\reports\\goals-wbr.html', encoding="utf8")
html = report_file.read()
part = MIMEText(html, 'html')
msg.attach(part)
#s is smtplib object
s.sendmail(msg['From'], msg['To'], msg.as_string())
<ul>
<li><a href="#00-team-update">team update</a></li>
<li><a href="#01-group-1">group 1</a></li>
<li><a href="#02-group-A">group A</a></li>
</ul>
<h2><a id="#00-team-update">team update</a></h2>
<h4 class="Green" style="color:black" bgcolor="#00FF00">
Internal links from HTML file are imported to mail body as hyperlinks, but links not working in the mail
Adding name attribute instead of id in solves the issue.