[GH-ISSUE #331] Configuring tags via config-file does not work #218

Closed
opened 2026-03-15 13:16:34 +03:00 by kerem · 4 comments
Owner

Originally created by @ppasieka on GitHub (Jul 7, 2024).
Original GitHub issue: https://github.com/axllent/mailpit/issues/331

I'm trying to configure the automatic tags assignment to emails.

My docker-compose looks like:

  mailpit:
    image: axllent/mailpit:latest
    restart: always
    ports:
      - "1025:1025"
      - "8025:8025"
    volumes:
      - ./mailpit-config.yaml:/config/mailpit-config.yaml
    environment:
      - MP_TAGS_CONFIG=/config/mailpit-config.yaml

And my mailpit-config.yaml looks like

filters:
  - match: [error-internal-server-error]
    keywords: EXCEPTION
  - match: [error-invalid-request]
    keywords: BAD REQUEST

I tried different variations on the match phrases (no braces, only single words, etc.), but nothing worked.

In the Mailpit application logs, I can see the following:

2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=warning msg="[tags] invalid tag () - can only contain spaces, letters, numbers, - & _"
2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=warning msg="[tags] invalid tag () - can only contain spaces, letters, numbers, - & _"
2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=info msg="[smtpd] starting on [::]:1025 (no encryption)"
2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=info msg="[http] starting on [::]:8025"
2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=info msg="[http] accessible via http://localhost:8025/"

When I use the environment variables to set tags, then tagging to works

  mailpit:
    image: axllent/mailpit:latest
    restart: always
    ports:
      - "1025:1025"
      - "8025:8025"
    environment:
      - MP_TAG="EXCEPTION=subject:[error-internal-server-error]"

Am I doing something wrong?

Originally created by @ppasieka on GitHub (Jul 7, 2024). Original GitHub issue: https://github.com/axllent/mailpit/issues/331 I'm trying to configure the automatic tags assignment to emails. My docker-compose looks like: ```yaml mailpit: image: axllent/mailpit:latest restart: always ports: - "1025:1025" - "8025:8025" volumes: - ./mailpit-config.yaml:/config/mailpit-config.yaml environment: - MP_TAGS_CONFIG=/config/mailpit-config.yaml ``` And my `mailpit-config.yaml` looks like ```yaml filters: - match: [error-internal-server-error] keywords: EXCEPTION - match: [error-invalid-request] keywords: BAD REQUEST ``` I tried different variations on the match phrases (no braces, only single words, etc.), but nothing worked. In the Mailpit application logs, I can see the following: ``` 2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=warning msg="[tags] invalid tag () - can only contain spaces, letters, numbers, - & _" 2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=warning msg="[tags] invalid tag () - can only contain spaces, letters, numbers, - & _" 2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=info msg="[smtpd] starting on [::]:1025 (no encryption)" 2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=info msg="[http] starting on [::]:8025" 2024-07-07 13:29:22 time="2024/07/07 11:29:22" level=info msg="[http] accessible via http://localhost:8025/" ``` When I use the environment variables to set tags, then tagging to works ```yaml mailpit: image: axllent/mailpit:latest restart: always ports: - "1025:1025" - "8025:8025" environment: - MP_TAG="EXCEPTION=subject:[error-internal-server-error]" ``` Am I doing something wrong?
kerem closed this issue 2026-03-15 13:16:39 +03:00
Author
Owner

@ppasieka commented on GitHub (Jul 7, 2024):

short python script to help test this out

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import random
import string

def generate_random_email():
    username = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
    domain = ''.join(random.choices(string.ascii_lowercase, k=6))
    return f"{username}@{domain}.com"

def generate_random_message():
    words = ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
    return ' '.join(random.choices(words, k=random.randint(5, 10)))

def send_email(subject, from_addr, to_addr, body):
    msg = MIMEMultipart()
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Subject'] = subject

    msg.attach(MIMEText(body, 'plain'))

    server = smtplib.SMTP('localhost', 1025)
    text = msg.as_string()
    server.send_message(msg)
    server.quit()

    print(f"Sent email: \nFrom: {from_addr}\nTo: {to_addr}\nSubject: {subject}\nBody: {body}\n")

def main():
    to_address = "test@example.com"  # You can change this to any email address

    # Send email with [error-internal-server-error] in subject
    send_email(
        subject="Hey! [error-internal-server-error] Test Email",
        from_addr=generate_random_email(),
        to_addr=to_address,
        body=generate_random_message()
    )

    # Send email with [error-invalid-request] in subject
    send_email(
        subject="Hey! [error-invalid-request] Another Test Email",
        from_addr=generate_random_email(),
        to_addr=to_address,
        body=generate_random_message()
    )

    # Send a normal email without special subject
    send_email(
        subject="Normal Test Email",
        from_addr=generate_random_email(),
        to_addr=to_address,
        body=generate_random_message()
    )

if __name__ == "__main__":
    main()
<!-- gh-comment-id:2212422084 --> @ppasieka commented on GitHub (Jul 7, 2024): short python script to help test this out ```python import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import random import string def generate_random_email(): username = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8)) domain = ''.join(random.choices(string.ascii_lowercase, k=6)) return f"{username}@{domain}.com" def generate_random_message(): words = ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'] return ' '.join(random.choices(words, k=random.randint(5, 10))) def send_email(subject, from_addr, to_addr, body): msg = MIMEMultipart() msg['From'] = from_addr msg['To'] = to_addr msg['Subject'] = subject msg.attach(MIMEText(body, 'plain')) server = smtplib.SMTP('localhost', 1025) text = msg.as_string() server.send_message(msg) server.quit() print(f"Sent email: \nFrom: {from_addr}\nTo: {to_addr}\nSubject: {subject}\nBody: {body}\n") def main(): to_address = "test@example.com" # You can change this to any email address # Send email with [error-internal-server-error] in subject send_email( subject="Hey! [error-internal-server-error] Test Email", from_addr=generate_random_email(), to_addr=to_address, body=generate_random_message() ) # Send email with [error-invalid-request] in subject send_email( subject="Hey! [error-invalid-request] Another Test Email", from_addr=generate_random_email(), to_addr=to_address, body=generate_random_message() ) # Send a normal email without special subject send_email( subject="Normal Test Email", from_addr=generate_random_email(), to_addr=to_address, body=generate_random_message() ) if __name__ == "__main__": main() ```
Author
Owner

@ppasieka commented on GitHub (Jul 7, 2024):

Ok. I found what is wrong: the documentation is outdated.

The YAML parser for tags expects the tags as a key, not keywords key:

type yamlTags struct {
	Filters []yamlTag `yaml:"filters"`
}

type yamlTag struct {
	Match string `yaml:"match"`
	Tags  string `yaml:"tags"`
}

Changing my mailpit-config.yaml content to:

filters:
  - match: error-internal-server-error
    tags: EXCEPTION
  - match: error-invalid-request
    tags: BAD REQUEST

And this makes it work!

<!-- gh-comment-id:2212428259 --> @ppasieka commented on GitHub (Jul 7, 2024): Ok. I found what is wrong: the documentation is outdated. The YAML parser for tags expects the `tags` as a key, not `keywords` key: ```go type yamlTags struct { Filters []yamlTag `yaml:"filters"` } type yamlTag struct { Match string `yaml:"match"` Tags string `yaml:"tags"` } ``` Changing my `mailpit-config.yaml` content to: ```yaml filters: - match: error-internal-server-error tags: EXCEPTION - match: error-invalid-request tags: BAD REQUEST ``` And this makes it work!
Author
Owner

@axllent commented on GitHub (Jul 7, 2024):

Ahh, damn, that keywords => tags is obviously my bad, I'll fix the documentation once I'm on my computer and can double check this. In addition to this, in yaml [] has a special meaning (an array). Try to quote your match values, eg match: "[error-internal-server-error]"

<!-- gh-comment-id:2212550387 --> @axllent commented on GitHub (Jul 7, 2024): Ahh, damn, that keywords => tags is obviously my bad, I'll fix the documentation once I'm on my computer and can double check this. In addition to this, in yaml `[]` has a special meaning (an array). Try to quote your match values, eg `match: "[error-internal-server-error]"`
Author
Owner

@axllent commented on GitHub (Jul 7, 2024):

You are absolutely correct @ppasieka, that was a very bad documentation mistake, especially considering that I use this feature myself. I sincerely apologise! I have fixed the documentation and added quotes to the example to hopefully help prevent others from making a similar mistake (eg: using []). I will close this issue, however please feel free to re-open it if you have any other issues. Thanks for the bug report!

<!-- gh-comment-id:2212582490 --> @axllent commented on GitHub (Jul 7, 2024): You are absolutely correct @ppasieka, that was a very bad documentation mistake, especially considering that I use this feature myself. I sincerely apologise! I have fixed [the documentation](https://mailpit.axllent.org/docs/usage/tagging/#set-filters-using-a-config) and added quotes to the example to hopefully help prevent others from making a similar mistake (eg: using `[]`). I will close this issue, however please feel free to re-open it if you have any other issues. Thanks for the bug report!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#218
No description provided.