1
我有以下代碼:Python - 閱讀電子郵件?
import poplib
mailServer = 'pop.gmail.com'
emailID = '[email protected]'
emailPass = 'pw'
myEmailConnection = poplib.POP3_SSL(mailServer)
print myEmailConnection.getwelcome()
myEmailConnection.user(emailID)
myEmailConnection.pass_(emailPass)
EmailInformation = myEmailConnection.stat()
print "Number of new emails: %s (%s bytes)" % EmailInformation
print "\n\n===\nRead messages\n===\n\n"
numberOfMails = EmailInformation[0]
for i in range(numberOfMails):
for email in myEmailConnection.retr(i+1)[1]:
print email
的代碼工作。 我可以閱讀我的所有消息。 但我的問題是我如何能得到身體作爲一個字符串? 是否可以將正文文本作爲String?
THX
您打印的是電子郵件的正文?此外,這個問題被標記爲「python-3.x」,但是用python編寫2 –
考慮閱讀關於Python [email](https://docs.python.org/2/library/email.html)模塊,其中包含解析電子郵件的代碼。 – larsks
解析器不適合我! :/ – Moe