Python Forum
get number of unread emails + email text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get number of unread emails + email text
#1
I am looking at using Python to access email.

Following this code I was surprised to find, it worked first time!

I am trying to save paper. What I want to do is get the actual text from the email and mark it.

On the this page he says:

"The message body can be obtained by calling msg.get_payload(), which will return the payload data as a string (if the message is not multi-part). "
Is this the best way to get the email text?

What module does msg.get_payload() belong to?

I need to know how many unread messages I have. How can I get that? (Something like: unread = number of unread messages)

Then I want to save each text in a for loop: (something like this, I've got to try it out first, don't laugh!)

for i in range(0, unread):
    saveFileName = str(i) + emailText
    open(saveFileName + '.txt', "w")
    message =  msg.get_payload()
    saveFileName.write(message)
    saveFileName.close
Reply
#2
msg is a variable that holds current message (in the code on page https://gist.github.com/robulouski/7441883)
if you look at the code of the page you reference, you will see:
msg = email.message_from_string(data[0][1])
as you can see, it holds result of calling method message_from_string from class email (which you import)
so package name is email and msg.get_payload() should be visible in that code.
Reply
#3
Thanks!

I haven't really got my head around this yet.

Is there a way to only look at unread messages, or will I have to empty the INBOX before I try this?
Reply
#4
Sorry, can't help here, I haven't used this package.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Brick Number stored as text with openpyxl CAD79 1 218 Mar-19-2024, 08:31 PM
Last Post: deanhystad
  Sending Emails on Autopilot Gyga_Hawk 3 1,627 Mar-15-2022, 08:20 AM
Last Post: Larz60+
  Search text in PDF and output its page number. atomxkai 21 8,680 Jan-21-2022, 06:20 AM
Last Post: snippsat
  Trying out the parsing/reading of emails from my outlook cubangt 0 6,053 Jan-12-2022, 08:59 PM
Last Post: cubangt
  Extracing unique email address from a folder of emails jehoshua 6 2,677 Oct-14-2020, 12:43 AM
Last Post: jehoshua
  reading shared outlook emails zarize 0 2,422 Mar-03-2020, 01:47 PM
Last Post: zarize
  Python Library for Reading POP Emails? bmccollum 1 3,562 Jan-06-2020, 06:37 PM
Last Post: micseydel
  Read in trades from emails semantina 2 2,065 Nov-06-2019, 06:12 PM
Last Post: semantina
  Split Column Text by Number of Characters cgoldstein 3 2,949 Mar-11-2019, 01:45 PM
Last Post: perfringo
  get the number in the line in text file lateublegende 2 2,452 Jan-29-2019, 06:03 PM
Last Post: lateublegende

Forum Jump:

User Panel Messages

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