5

I am using the imaplib of python to get emails from a server. These emails will be forwarded. Based on the total size of the individual email the attachments will be dropped or forwarded with the message. But how do I get the total size of a email.message?

I found this answer, but it does not apply as I do not get the email from a file: find the total size of an email message using the email package

This is how I get the email:

m = imaplib.IMAP4_SSL(self.imap_server, int(self.imap_port))
m.select("Inbox") 

resp, items = m.search(None, "UNSEEN")
items = items[0].split()

for emailid in items:
    resp, data = m.fetch(emailid, "(RFC822)")
    mail = email.message_from_bytes(data[0][1])
    #TODO: get size of email
Community
  • 1
  • 1
MartinM
  • 129
  • 1
  • 8

0 Answers0