ragarupa Anumolu
ragarupa Anumolu

Reputation: 3

Python error: ''ModuleNotFoundError: No module named 'email.Utils''

import fileinput
import email
from email.Utils import parseaddr

def parse():
    raw_message = ''.join([line for line in fileinput.input()])
    message = email.message_from_string(raw_message)
    text_plain = None
    text_html = None

for part in message.walk():
    if part.get_content_type() == 'text/plain' and text_plain is None:
        text_plain = part.get_payload()
    if part.get_content_type() == 'text/html' and text_html is None:
        text_html = part.get_payload()

return {
  'to': parseaddr(message.get('To'))[1],
  'from': parseaddr(message.get('From'))[1],
  'delivered to': parseaddr(message.get('Delivered-To'))[1],
  'subject': message.get('Subject'),
  'text_plain': text_plain,
  'text_html': text_html,
}

if __name__ == '__main__':
    print(parse())

this is my code I am trying to make an email parser and I imported email and I installed email module using pip and I use python 3.9 I tried eveything to fix it, is there any answer or altervatives? PS. this is not the whole code

Upvotes: 0

Views: 1789

Answers (1)

DapperDuck
DapperDuck

Reputation: 2859

Utils should not be capitalized. Here is the corrected line:

from email.utils import parseaddr

Source: https://docs.python.org/3/library/email.utils.html

Upvotes: 1

Related Questions