Email messages

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

Watermarker.get_content() returns an EmailContent for an email message (MSG, EML, EMLX). It exposes the message body, html_body, and subject, the embedded_objects (inline images), the recipient lists (to, cc, bcc), and the attachments.

Modify the body and subject

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.email import EmailLoadOptions

def modify_message():
    with Watermarker("./message.msg", EmailLoadOptions()) as watermarker:
        content = watermarker.get_content()
        content.subject = content.subject + " [CONFIDENTIAL]"
        content.body = content.body + "\n\nThis message is confidential."
        watermarker.save("./output.msg")

if __name__ == "__main__":
    modify_message()

message.msg is the sample file used in this example. Click here to download it.

Binary file (MSG, 292 KB)

Download full output

Embed an image into the body

Add the image to embedded_objects, then reference it from the HTML body by its content id:

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.email import EmailLoadOptions

def embed_image():
    with Watermarker("./message.msg", EmailLoadOptions()) as watermarker:
        content = watermarker.get_content()
        with open("./logo.png", "rb") as f:
            data = f.read()
        content.embedded_objects.add(data, "logo.png")
        embedded = content.embedded_objects[len(content.embedded_objects) - 1]
        content.html_body = content.html_body.replace(
            "</body>", f'<img src="cid:{embedded.content_id}"/></body>')
        watermarker.save("./output.msg")

if __name__ == "__main__":
    embed_image()

message.msg and logo.png are the sample files used in this example. Download message.msg and logo.png.

Binary file (MSG, 301 KB)

Download full output

Search the message text

Limit the search to the subject and body, then search with a TextSearchCriteria:

from groupdocs.watermark import Watermarker, WatermarkerSettings
from groupdocs.watermark.search.search_criteria import TextSearchCriteria
from groupdocs.watermark.search.objects import SearchableObjects, EmailSearchableObjects

def search_message_text():
    settings = WatermarkerSettings()
    settings.searchable_objects = SearchableObjects(
        email_searchable_objects=EmailSearchableObjects.SUBJECT | EmailSearchableObjects.PLAIN_TEXT_BODY)

    with Watermarker("./message.msg", settings) as watermarker:
        possible = watermarker.search(TextSearchCriteria("confidential"))
        print("Found", len(possible), "match(es)")

if __name__ == "__main__":
    search_message_text()

message.msg is the sample file used in this example. Click here to download it.

Found 2 match(es)

Download full output

List recipients

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.email import EmailLoadOptions

def list_recipients():
    with Watermarker("./message.msg", EmailLoadOptions()) as watermarker:
        content = watermarker.get_content()
        for recipient in list(content.to) + list(content.cc) + list(content.bcc):
            print(recipient.address)

if __name__ == "__main__":
    list_recipients()

message.msg is the sample file used in this example. Click here to download it.

alex.chen@northwind.example
priya.natarajan@northwind.example
tomas.reyes@auroravisuals.example
archive@auroravisuals.example

Download full output