Hi everyone.
I am trying to build a Basecamp-ish application where Ignition would associate notes, files, comments, and emails to a particular thread in the client’s database. In Basecamp, comments are posted in connection to a “To Do” item, and you can send copies of that comment to external email recipients.
Easy enough.
BUT, when one of the recipients replies to that email, it goes back to Basecamp, gets saved in the thread, and then the Basecamp email handler notifies everyone else who was on the distribution for that comment. This requires that Basecamp can handle both outgoing and incoming email.
It’s the incoming email part that has me scratching my head… What is the best way for an Ignition project to be able to receive emails (or listen to an email Inbox) so that an event script can be fired when Ignition sees that an email has been received?
the email to db software looks like an easy solution. I could see having it push the emails to a table and having a boolean column in the table to indicate if the message has been processed. you can then query the table with a gateway timer script every minute or so to see if any rows exist with processed = 0. have your script do what it needs to do with the email message and then write the processed to 1… rinse and repeat.
I was able to get as far as it logging into my gmail account and telling me how many unread messages I had. Its bedtime now though!
Ok I dont give up that easy. Thi s was able to grab a list of unread messages and print the body
import imaplib
username = 'yourusername@gmail.com'
password = 'yourpassword'
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
imap_server.login(username, password)
imap_server.select('INBOX')
status, response = imap_server.status('INBOX', "(UNSEEN)")
unreadcount = int(response[0].split()[2].strip(').,]'))
print unreadcount
status, email_ids = imap_server.search(None, '(UNSEEN)')
print email_ids
for i in email_ids[0].split(' '): #not sure why, but the email ids didnt come back in a list as expected, they came back like '1 2 3 4'
response = imap_server.fetch(i, '(UID BODY[TEXT])')
print response