Python Forum
get email text body: very close but I can't get it [SOLVED}
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get email text body: very close but I can't get it [SOLVED}
#5
Well, solved it for my needs in the end.

It seems you cannot put a loop variable in 'server.fetch([loopVariable], ['BODY[]', 'FLAGS'])' I suppose that it is not translated then sent to the imap server, but sent directly.

Now I can print the email body content, I can save it to a text file. The rest does not involve email or internet, I can handle that.

import pyzmail
import pprint
from imapclient import IMAPClient
 
server = IMAPClient('imap.qq.com', use_uid=True, ssl=True)
server.login('[email protected]', 'myIMAPpassword')
select_info = server.select_folder('Inbox')
 
#server.search(['SINCE', '07-Oct-2018'])

unseenMessages = server.search(['UNSEEN'])

#rawMessage = server.fetch([57], ['BODY[]', 'FLAGS'])
rawMessage = server.fetch(unseenMessages, ['BODY[]', 'FLAGS']) 
#print(rawMessage)
#print(message.get_payload(1))
 
#message = pyzmail.PyzMessage.factory(rawMessage[57][b'BODY[]'])
#message.text_part.get_payload().decode(message.text_part.charset)

#print(message.get_payload())

for msgNum in unseenMessages:
	message = pyzmail.PyzMessage.factory(rawMessage[msgNum][b'BODY[]'])
	text = message.text_part.get_payload().decode(message.text_part.charset)
	print('Text' + str(msgNum) + ' = ')
	print(text)
Reply


Messages In This Thread
RE: get email text body: very close but I can't get it - by Pedroski55 - Oct-07-2018, 10:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [BeautifulSoup] How to get this text? Winfried 6 3,117 Aug-17-2022, 03:58 PM
Last Post: Winfried
  Delete empty text files [SOLVED] AlphaInc 5 3,129 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  [SOLVED] [ElementTree] Grab text in attributes? Winfried 3 2,502 May-27-2022, 04:59 PM
Last Post: Winfried
  [SOLVED] Read text file from some point till EOF? Winfried 1 3,539 Oct-10-2021, 10:29 PM
Last Post: Winfried
  Sorting and Merging text-files [SOLVED] AlphaInc 10 7,836 Aug-20-2021, 05:42 PM
Last Post: snippsat
Thumbs Up [SOLVED] Find last occurence of pattern in text file? Winfried 4 6,554 Aug-13-2021, 08:21 PM
Last Post: Winfried
  Replace String in multiple text-files [SOLVED] AlphaInc 5 11,136 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  A text-based game [SOLVED] Gameri1 6 5,260 Apr-20-2021, 02:26 PM
Last Post: buran
  How to Save Full Email Body to CLOB in Oracle w/Carriage Returns? bmccollum 1 2,954 Mar-12-2020, 10:25 PM
Last Post: Larz60+
  Zeep lib, encrypt soap body miha1234 0 3,381 Sep-12-2019, 07:52 AM
Last Post: miha1234

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020