Suggestions on programming in Python an email simple client

Maroso Marco androidmaroso at gmail.com
Tue Feb 13 15:05:58 EST 2018


Hi,

what i'm trying to do is develop my own email client, but a simple one.

I just want it to connect to a specific email account and read the subject line of messages coming from a certain email address.

I then want it to be able to execute the command i wrote on the subject.

It would be nice if i could specify two parameters on the subject line

first : password;
second : command;

The first parameter is the password and the second is the command to be executed in the local pc where this program is running.

The program will have to show only email coming from a specific account
and if the mail is unread then it should read the subject line and find parameters.
The first parameter must match my hardcoded password, and the second parameter must be executed on the local pc (example ... c:\windows\notepad.exe)

It must check for new emails at a given timing (example ...every 30 seconds )
 (the timing can be hardcoded or specified in a separate file)

This is it.

Any suggestions?

I have started doing this (but i never programmed in python before):


import imaplib
import os
import email
import email.header

plusmail = "emailaddresstobechecked at gmail.com"
googlepass = "mypassword"
owner = "validsender at gmail.com"

M = imaplib.IMAP4_SSL('imap.gmail.com')
M.login(plusmail, googlepass)
M.select()

status, response = M.search(None, '(UNSEEN)')
unread_msg_nums = response[0].split()

# Print the count of all unread messages
print (len(unread_msg_nums))

# Print all unread messages from a certain sender of interest
status, response = M.search(None, '(UNSEEN)', '(FROM "%s")' % (owner))
unread_msg_nums = response[0].split()
da = []
for e_id in unread_msg_nums:
    _, response = imap.fetch(e_id, '(BODY.PEEK[HEADER.FIELDS (From Subject)] RFC822.SIZE)')
    da.append(response[0][1])
# print (da)

# Mark them as seen
for e_id in unread_msg_nums:
    imap.store(e_id, '+FLAGS', '\Seen')


    
typ, data = M.search(None, 'From',(owner))
for num in data[0].split():
    typ, data = M.fetch(num, '(RFC822)')
    print ('Message %s\n%s\n' % (num, data[0][1]))
M.close()
M.logout()

I know there are duplicates but i need to figure out how to build this correctly 


Thanks in advance for any help given.



More information about the Python-list mailing list