python-3.xrfc822

ModuleNotFoundError: No module named 'rfc822'


I trying to read my email python version 3.6.9 and pip3 version 9.0.1. when i run the following script it returns the error shows below. I try to install rfc822 with pip and pip3. Can you please help me to solve this issue.

Many thanks Erik

ERROR

    Traceback (most recent call last):
  File "/home/webapp/git/RA Functions/test.py", line 3, in <module>
    import rfc822
ModuleNotFoundError: No module named 'rfc822'

CODE

import poplib
import string, random
import rfc822
from io import StringIO

def readMail(): 
    SERVER = "pop.gmail.com"
    USER = "myemail@gmail.com"
    PASSWORD = "mypassword"

    # connect to server
    server = poplib.POP3(SERVER)

    # login
    server.user(USER)
    server.pass_(PASSWORD)

    # list items on server
    resp, items, octets = server.list()

    for i in range(0,10):
        id, size = string.split(items[i])
        resp, text, octets = server.retr(id)

        text = string.join(text, "\n")
        file = StringIO.StringIO(text)

        message = rfc822.Message(file)

        for k, v in message.items():
            print(k, "=", v)

readMail()

Solution

  • This module is deprecated since version 2.3: The email package should be used in preference to the rfc822 module. This module is present only to maintain backward compatibility, and has been removed in Python 3.

    For more information visit this : Deprecated Link

    But here is another module which is plone.rfc822

    This package provides primitives for turning content objects described by zope.schema fields into RFC (2)822 style messages. It utilizes the Python standard library’s email module.

    For installation: pip install plone.rfc822

    For information visit this: Active Link