Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python 3.6阅读电子邮件正文文本_Python_Python 3.x_Imaplib - Fatal编程技术网

使用python 3.6阅读电子邮件正文文本

使用python 3.6阅读电子邮件正文文本,python,python-3.x,imaplib,Python,Python 3.x,Imaplib,我正试图得到我的gmail上发送的确切文本,但我也得到了一些其他值,下面是我的代码 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(cont

我正试图得到我的gmail上发送的确切文本,但我也得到了一些其他值,下面是我的代码

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--
--001a11443f6015ac310559254049
内容类型:文本/纯文本;charset=“UTF-8”
你好
--001a11443f6015ac310559254049
内容类型:text/html;charset=“UTF-8”
你好
--001a11443f6015ac310559254049--

但是我的留言只是你好

我用过这个方法



显然,我的消息没有任何新行。但是如果你有,你可以试试这个



我对Python非常陌生,所以我没有高级知识,但现在这一个非常好用


希望有帮助。

我用过这个方法



显然,我的消息没有任何新行。但是如果你有,你可以试试这个



我对Python非常陌生,所以我没有高级知识,但现在这一个非常好用

希望能有帮助

v = data[0][1].decode()
w = v.split('\n')

message = w[5]
v = data[0][1].decode()
w = v.split('\n')

message = ''

for i in range(i-5,(len(w)-2)):
   message = message + w[i] + '\n'