# Ignition as an email parser?

**URL:** <https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539>\
**Category:** Ignition\
**Created:** [September 28, 2015, 8:05pm UTC](https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539 "2015-09-28T20:05:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cas](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Cas](https://forum.inductiveautomation.com/u/Cas)\
**Post date:** [September 28, 2015, 8:05pm UTC](https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539/1 "2015-09-28T20:05:04Z")

</div>

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?

Kinda like this idea: [http://www.email2db.com](http://www.email2db.com)

Any ideas?

Thanks,  
Cas

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 29, 2015, 1:03am UTC](https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539/2 "2015-09-29T01:03:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cas](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Cas](https://forum.inductiveautomation.com/u/Cas)\
**Post date:** [September 29, 2015, 2:22am UTC](https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539/3 "2015-09-29T02:22:54Z")

</div>

Diat150,  
I was thinking about the same setup, but would like to avoid the need for the email-to-db software…

I’m wondering if Ignition can do that job too.

MC

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 29, 2015, 3:45am UTC](https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539/4 "2015-09-29T03:45:55Z")

</div>

[quote=“Cas”]Diat150,  
I was thinking about the same setup, but would like to avoid the need for the email-to-db software…

I’m wondering if Ignition can do that job too.

MC[/quote]

It definitely seems possible.

Take a look at this

[pymotw.com/2/imaplib/](https://pymotw.com/2/imaplib/)

and this

[bitsofpy.blogspot.com/2010/05/py … -imap.html](http://bitsofpy.blogspot.com/2010/05/python-and-gmail-with-imap.html)

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Cas](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Cas](https://forum.inductiveautomation.com/u/Cas)\
**Post date:** [September 30, 2015, 1:47pm UTC](https://forum.inductiveautomation.com/t/ignition-as-an-email-parser/10539/5 "2015-09-30T13:47:22Z")

</div>

Diat150,  
Awesome. Thanks for pointing me in the right direction - this seems like it will do the trick!  
Take care,  
Cas
