IMAP

After creating an IMAP connection messages can be fetched, mark as seen and deleted as below.

Receiving e-mails

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        conn = self.email.imap.get('My Connection').conn

        for msg_id, msg in conn.get():

            # Access the message
            self.logger.info(msg.data)

Marking messages seen

Call .mark_seen() on a message object to mark it as seen.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        conn = self.email.imap.get('My Connection').conn

        for msg_id, msg in conn.get():

            # Access the message
            self.logger.info(msg.data)

            # To mark the message seen
            msg.mark_seen()

Deleting messages

Call .delete() on a message object to mark it as seen.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        conn = self.email.imap.get('My Connection').conn

        for msg_id, msg in conn.get():

            # Access the message
            self.logger.info(msg.data)

            # To delete the message
            msg.delete()