Since the forwarding function of the mailbox can only be forwarded to the specified mailbox, and the content of the mail cannot be filtered, so I wrote the automatic mail forwarding tool ForMaiR while the leader was away.

ForMaiR: auto Forward eMails with custom Rules

Automatic mail forwarding tool with user-defined rules.

use

# Clone code repository
git clone [email protected]:hsowan/ForMaiR.git
cd ForMaiR

# copy a configuration file from template/config.yaml
cp template/config.yaml config.yaml

Initialize the python3 environment
virtualenv -p python3 .venv
source .venv/bin/activate

# install dependencies
pip install -r requirements.txt

# Start forwarding emails according to user-defined rules
python main.py config.yaml
Copy the code

Custom rules

Messages that meet any of the following rules are forwarded to the specified mailbox list (TO_ADDRS)

  • Who sent the message (from_addr[1]) in the specified sender list (from_addrs)
  • Subject of the message (subjectMatches the specified topic regular expression (subject_pattern)
  • Content of the Email (plain_contenthtml_contentMatches the specified content regular expression (content_pattern)
rules:
  -
    to_addrs:
      - '[email protected]'
      - '[email protected]'
    from_addrs:
      - '[email protected]'
      - '[email protected]'
    subject_pattern: ' '
    content_pattern: ' '
  -
    to_addrs:
      - '[email protected]'
      - '[email protected]'
    from_addrs:
      - '[email protected]'
      - '[email protected]'
    subject_pattern: ' '
    content_pattern: ' '
Copy the code

Forward only new messages

Supports forwarding new messages within a specified range.

  • fromindex_fileFile to get the last message read location (last_email_index) (Default is 0 if the file does not exist)
  • frompop3_server.statGet the total number of current messages (email_count)
for index in range(last_email_index+1, email_count+1) :pass
Copy the code

Open source code

  • GitHub
  • Yards cloud

The document address

formair.io

Original link: k8scat.com/posts/forma…