1
我想獲取發送到我的Gmail的確切文本,但我也得到了其他值,以下是我的代碼。使用python讀取電子郵件正文文本3.6
import imaplib
server = imaplib.IMAP4_SSL ('imap.gmail.com', 993)
username = 'email'
password = 'pass'
server.login(username, password)
stat , content = server.select('Inbox')
stat , data = server.fetch(content[0],'(UID BODY[TEXT])')
print (data[0][1].decode())
server.close()
server.logout()
在這種情況下我的輸出是
--001a11443f6015ac310559254049
Content-Type: text/plain; charset="UTF-8"
hello
--001a11443f6015ac310559254049
Content-Type: text/html; charset="UTF-8"
<div dir="auto">hello</div>
--001a11443f6015ac310559254049--
但我的消息只是招呼
https://stackoverflow.com/questions/2230037/how-to-fetch-an-email-body-using-imaplib-in-python – IsaacDj