get number of unread emails + email text - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: get number of unread emails + email text (/thread-13212.html) |
get number of unread emails + email text - Pedroski55 - Oct-04-2018 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 RE: get number of unread emails + email text - Larz60+ - Oct-04-2018 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. RE: get number of unread emails + email text - Pedroski55 - Oct-04-2018 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? RE: get number of unread emails + email text - Larz60+ - Oct-04-2018 Sorry, can't help here, I haven't used this package. |