Python IMAP - Read Gmail with '+' in email address -
I previously used imaplib in Python 3 which removes email from Gmail. However, I want to generate a script to separate the email at the same address with different strings after the plus sign. For example, the base email address may be:
example @ gmail .com
Then I want to read different email addresses with addresses:
example+test1@gmail.com, example + test2 @ Gmail.com, example@gmail.com.
So I will end up with a dictionary of lists containing specific emails, it only works for example@gmail.com
. For example:
{'example': [], 'example_test': [], 'example_test2': []}
Currently I I can retrieve the emails I want from a class with this function:
def get_emails (self): "" retrieve email "" self. M = imaplib.IMAP4_SSL (self-propelled) self M.login (self.emailaddress, self.password) self.M.select (readonly = 1) self.M.select ('INBOX', Readonly = True) # YorkTard Date Date = (datetime.date.today () - Dtetime.timedelta (self.daysback)). Receive all emails from the results from "String" ("% d-% b-% Y") print ("Select email messages since% s"% date) #date = self.midid ('search' Returns, Data
You must use an exact match address directly in the IMAP search request. For example, something like this might happen:
result, data = self.mid ('search', none, '(sensor {date})' format (date = date) ('To example'test1@gmail.com'))
Comments
Post a Comment