Send a message to a channel when new emails arrive in an email account

Hi there, is there an app out there for Rocket Chat that can send a message to a channel whenever a new email arrives in a specified email account?

And better yet, can send a message to a channel whenever an email arrives in a specified email account matching specific subject or body text?


we use this simple Python script to automate this task:

#!/usr/bin/env python3

import email
import imaplib
import sys
from email.header import decode_header

import requests

from secrets import *

imap = imaplib.IMAP4_SSL("")
imap.login(username, password)

status, messages ="INBOX")

if status != "OK":
    print("Could not connect to INBOX")

count = int(messages[0])

for i in range(1, count + 1):
    # Fetch only the headers, the body does no matter for us
    res, msg = imap.fetch(str(i), "(RFC822.HEADER)")

    if res != "OK":
        print("Error with message object:", res, msg)

    for response in msg:
        if isinstance(response, tuple):
            msg = email.message_from_bytes(response[1])

            # Decode the subject header and reassemble afterwards
            subject_header = decode_header(msg["Subject"])
            subject = ""
            for value, encoding in subject_header:
                if isinstance(value, bytes):
                    if encoding is not None:
                        subject += value.decode(encoding, errors="ignore")
                        subject += value.decode("L1", errors="ignore")
                    subject += value

            # Decode the from header and reassemble afterwards
            from_header = decode_header(msg.get("From"))
            sender = ""
            for value, encoding in from_header:
                if isinstance(value, bytes):
                    if encoding is not None:
                        sender += value.decode(encoding, errors="ignore")
                        sender += value.decode("L1", errors="ignore")
                    sender += value

            mail = {
                "text": f"Neue Email von {sender}:",
                "attachments": [
                        "text": subject
  , url=rocket_hook), '+FLAGS', '\\Deleted')


Please note, that this script does only work if every processed email gets deleted (the script does that). So you will need to setup a shadow copy email account for this script to run on.