Email messages
Leave feedback
On this page
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.
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, 134 KB)
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, 142 KB)
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 0 match(es)
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
tomas.reyes@auroravisuals.example
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.