I can download the eml file using mime-content. I need to edit this eml file and delete attachments. I can look up attachment names. If I understand correctly, the first is the email header, the body, and then the attachments. I need advice on how to delete attachments from the body of an email.
import email
from email import policy
from email.parser import BytesParser
with open('messag.eml', 'rb') as fp: # select a specific email file
msg = BytesParser(policy=policy.default).parse(fp)
text = msg.get_body(preferencelist=('plain')).get_content()
print(text) # print the email content
for attachment in attachments:
fnam=attachment.get_filename()
print(fnam) #print attachment name
email
API has changed considerably since then, I'm posting a new answer here, and leaving a pointer at the old question. – Waksman