Question : Python: how to check mail status

Hi experts,

I am going to write a Python code to upload new e-mails from a specific user account into MySQL database. This Python code is scheduled to run every miniute.

This user account is generic so nobody will come to check e-mails except the running code. Whenever the code runs, it should only upload NEW e-mails into database. In other words, the code can not upload a e-mail content if this e-mail is in the database already. Therefore I need to know how to distinguish if a e-mail has been "read" by the code or not.

Comparing "From", "To" and "Body" of a e-mail with corresponding parts in the database is certainly a way to find if that e-mail has been loaded or not, however this method is too clumsy to use. Is there any smart way to find this?

Thanks so much.

Answer : Python: how to check mail status

In the above post I have ommited the ON DUPLICATE KEY part in the first approach (3a).

So the complete 3a answer is:

a) Use the insert query with ON DUPLICATE KEY and a dummy update part - in case that the entry exist the database will not complain nor do anything else - this is the silent approach.

"""INSERT INTO emails (e_to, e_from, e_subject, e_date, e_body) VALUES ('%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE e_date = e_date""" % (e_to, e_from, e_subject, e_date, e_body)

more info for ON DUPLICATE KEY at: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

*Also the table create has different fields from the ones I use later on the examples but this is trivial to change.
Random Solutions  
 
programming4us programming4us