Python Forum
No output for the code to read emails
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No output for the code to read emails
#7
This is the code I tried to extract only Subject and senders name.
import imaplib
import email

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('user_name','password')
mail.list()
mail.select('INBOX')
typ, data = mail.search(None,'ALL')

for i in data[0].split():
	typ, data = mail.fetch(i, '(RFC822)')
	
	for response_part in data:
		if isinstance(response_part, tuple):
			msg = email.message_from_string(str(response_part[1]))
			varSubject = msg['subject']
			varFrom = msg['from']
			print('[ %s ] %s' %(varFrom, varSubject))
This is the output I'm getting.
Output:
[ None ] None [ None ] None [ None ] None [ None ] None [ None ] None [ None ] None [ None ] None [ None ] None
Can anyone tell me what's wrong with the code?
Reply


Messages In This Thread
RE: No output for the code to read emails - by avani9659 - Aug-14-2018, 08:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 540 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  I cannot able to see output of this code ted 1 866 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Read All Emails from Outlook and add the word counts to a DataFrame sanaman_2000 0 2,012 Sep-15-2022, 07:32 AM
Last Post: sanaman_2000
  why I dont get any output from this code William369 2 1,254 Jun-23-2022, 09:18 PM
Last Post: William369
  Sending Emails on Autopilot Gyga_Hawk 3 1,850 Mar-15-2022, 08:20 AM
Last Post: Larz60+
  How can I organize my code according to output that I want ilknurg 1 1,276 Mar-11-2022, 09:24 AM
Last Post: perfringo
  Mark outlook emails as read using Python! shane88 2 6,896 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,576 Feb-13-2022, 07:13 PM
Last Post: menator01
  Trying out the parsing/reading of emails from my outlook cubangt 0 6,514 Jan-12-2022, 08:59 PM
Last Post: cubangt
  How to read this code? Jlyk 3 1,798 Aug-19-2021, 06:10 AM
Last Post: Jlyk

Forum Jump:

User Panel Messages

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