imaplib

imaplib - What is the correct folder name for Archive/All Mail in Gmail?

 ̄綄美尐妖づ 提交于 2020-01-02 06:23:06
问题 I have a script which exports all the email in Gmail as text files. It works fine with this line where you select the folder: mail.select("inbox") But I am not sure what the name is for Gmail's archive, where all of the email is stored. I've tried archive and all mail and stuff, but no luck. Anyone know the correct name? 回答1: Solved it. It is [Gmail]/All Mail or, if you are a Gmail UK user like me, it may be [Google Mail]/All Mail , because Gmail used to be called Google Mail in the UK due to

Why can't I login to an imap server twice in Python

こ雲淡風輕ζ 提交于 2020-01-02 04:16:46
问题 As the error message below states, I cannot log in because I'm in state LOGOUT and not in state NONAUTH. How do I get from LOGOUT to NONAUTH? Example below (obviously the login credentials are faked below) Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import imaplib >>> imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993) >>> imap_server.login('something@myserver.com', 'mypassword') ('OK', [

Certificate Authority for imaplib and poplib python

 ̄綄美尐妖づ 提交于 2020-01-01 17:07:28
问题 I'm using imaplib and poplib to perform email collection using IMAPS and POP3S for a secure connection. But from what I've been able to determine, neither library uses a CA to confirm the validity of the certificate received. It this true? If it is, is it possible to set imaplib or poplib to use a CA? If it's not true and they do use a CA, can someone please tell me how imaplib/poplib do it? Thanks. 回答1: A quick check of imaplib.py shows that it uses ssl.wrap_socket() to implement the IMAP

Certificate Authority for imaplib and poplib python

ぃ、小莉子 提交于 2020-01-01 17:07:08
问题 I'm using imaplib and poplib to perform email collection using IMAPS and POP3S for a secure connection. But from what I've been able to determine, neither library uses a CA to confirm the validity of the certificate received. It this true? If it is, is it possible to set imaplib or poplib to use a CA? If it's not true and they do use a CA, can someone please tell me how imaplib/poplib do it? Thanks. 回答1: A quick check of imaplib.py shows that it uses ssl.wrap_socket() to implement the IMAP

Get only NEW Emails imaplib and python

情到浓时终转凉″ 提交于 2019-12-28 08:08:29
问题 This is a smaller portion of a bigger project. I need to only get unread emails and a parse their headers. How can I modify the following script to only get unread emails? conn = imaplib.IMAP4_SSL(imap_server) conn.login(imap_user, imap_password) status, messages = conn.select('INBOX') if status != "OK": print "Incorrect mail box" exit() print messages 回答1: Something like this will do the trick. conn = imaplib.IMAP4_SSL(imap_server) try: (retcode, capabilities) = conn.login(imap_user, imap

Python email quoted-printable encoding problem

Deadly 提交于 2019-12-28 06:50:26
问题 I am extracting emails from Gmail using the following: def getMsgs(): try: conn = imaplib.IMAP4_SSL("imap.gmail.com", 993) except: print 'Failed to connect' print 'Is your internet connection working?' sys.exit() try: conn.login(username, password) except: print 'Failed to login' print 'Is the username and password correct?' sys.exit() conn.select('Inbox') # typ, data = conn.search(None, '(UNSEEN SUBJECT "%s")' % subject) typ, data = conn.search(None, '(SUBJECT "%s")' % subject) for num in

I want to grab all emails from an inbox using the Python IMAPLIB module… how can I do this?

别说谁变了你拦得住时间么 提交于 2019-12-25 18:23:13
问题 This is where I am at, but I'm not sure where to go from here: import imaplib import email conn = imaplib.IMAP4() conn.login("username", "password") status, messages = conn.select('INBOX') if status != "OK": print ("Incorrect mail box") exit() print (messages) 回答1: I have test it under gmx and it works, please take a look at https://docs.python.org/3/library/email.html and https://docs.python.org/3/library/imaplib.html import imaplib import email mail = imaplib.IMAP4_SSL('imap') mail.login(

Only show certain number of emails in imaplib

大城市里の小女人 提交于 2019-12-25 08:57:11
问题 The code I have below is working great but I am testing this on a test email and it only have around 5 emails. On my actual email account I have atleast 4k emails on my inbox. Is there a way for me to show for a certain number of emails. For example, only show the first 20 most recent emails? And then after that say when a button is clicked it will show the next 20 emails... import sys import imaplib import getpass import email import email.header import datetime email_address = "email

Errors receiving emails with imaplib, from a specific inbox

微笑、不失礼 提交于 2019-12-24 06:44:49
问题 When reading emails from a specific folder (Office365), the body of the message is a random long string that makes no sense. Initially, I sent those emails to my personal mail as copy, to a specific folder. Reading from there I haven't had problems. But when I try to read directly from the main inbox, the messages are long strings that makes no sense (so, I can´t parse anything) mail = imaplib.IMAP4_SSL(SMTP_SERVER) mail.login(FROM_EMAIL, FROM_PWD) boxes = mail.list() mail.select('INBOX

How to catch socket timeout in Python 3?

淺唱寂寞╮ 提交于 2019-12-23 02:38:33
问题 Part of my script: def testConnection(self): # This code doesn't work try: self.imap.login(self.user, self.password) return True except: return False When I try to connect with imaplib to mail server with wrong settings, script always crashes with this error: Traceback (most recent call last): File "./mail-notifier.py", line 198, in <module> mail_check() File "./mail-notifier.py", line 161, in mail_check if (SettingsExist() == True and Mail().testConnection() == True): File "./mail-notifier