Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fetch email from gmail using python site:stackoverflow.com

import imaplib
import email
import datetime
import time

mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
mail.login(user, password)
mail.list()
mail.select('inbox')

status, data = mail.search(None, 'ALL')
for num in data[0].split():
    status, data = mail.fetch(num, '(RFC822)')
    email_msg = data[0][1]
    email_msg = email.message_from_bytes(email_msg)
    maintype = email_msg.get_content_maintype()
    if maintype == 'multipart':
        for part in email_msg.get_payload():
            if part.get_content_maintype() == 'text':
                print(part.get_payload())
    elif maintype == 'text':
        print(email_msg.get_payload())
Comment

PREVIOUS NEXT
Code Example
Python :: list the available fonts matplotlib 
Python :: python iterate set 
Python :: lower upper in pytho 
Python :: How to do train test split in keras Imagedatagenerator 
Python :: import qq plot 
Python :: max date by group pandas 
Python :: python pip jupyter notebook install 
Python :: openpyxl load file 
Python :: datetime library 
Python :: removing whitespaces from pandas dataframe csv 
Python :: complex arrays python 
Python :: python comment block 
Python :: get variable name python 
Python :: remove first 3 columns pandas 
Python :: python round down 
Python :: python shortest distance between two points 
Python :: remove nans and infs python 
Python :: python list splicing 
Python :: pandas apply function to each row lambda 
Python :: df dropna 
Python :: convert column series to datetime in pandas dataframe 
Python :: models. type for phone number in django 
Python :: how to simplify fraction in python 
Python :: Python program to print all odd numbers in a range 
Python :: drop list of columns pandas 
Python :: django view 
Python :: .argsort() python 
Python :: python program to add two numbers using function 
Python :: newsapi in python 
Python :: what is seaborn in python 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =