I write a python script to read the emails but it is not working.I am getting library errors. I enabled imap and pop in email. currently i am using ubuntu os . I tried to run this script using python and python3 both but still i am getting these errors.
import imaplib
import base64
email_user = input('Email: ')
email_pass = input('Password: ')
M = imaplib.IMAP4_SSL('imap.gmail',993)
M.login(email_user, email_pass)
M.select()
typ, message_numbers = M.search(None, 'ALL') # change variable name, and use new name in for loop
for num in message_numbers[0].split():
typ, data = M.fetch(num, 'RFC822')
num1 = base64.b64decode(num) # unnecessary, I think
print(data) # check what you've actually got. That will help with the next line
data1 = base64.b64decode(data[0][1])
print('Message %s\n%s\n' % (num, data1))
M.close()
M.logout()
i am getting these errors
Traceback (most recent call last):
File "imapgit.py", line 6, in <module>
M = imaplib.IMAP4_SSL('imap.gmail',993)
File "/usr/lib/python3.6/imaplib.py", line 1288, in __init__
IMAP4.__init__(self, host, port)
File "/usr/lib/python3.6/imaplib.py", line 198, in __init__
self.open(host, port)
File "/usr/lib/python3.6/imaplib.py", line 1301, in open
IMAP4.open(self, host, port)
File "/usr/lib/python3.6/imaplib.py", line 299, in open
self.sock = self._create_socket()
File "/usr/lib/python3.6/imaplib.py", line 1291, in _create_socket
sock = IMAP4._create_socket(self)
File "/usr/lib/python3.6/imaplib.py", line 289, in _create_socket
return socket.create_connection((host, self.port))
File "/usr/lib/python3.6/socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known