Email attachments
Leave feedback
On this page
import os
import groupdocs.watermark as gw
import groupdocs.watermark.contents.email as gwc_email
output_dir = os.path.join("SampleFiles", "Output")
os.makedirs(output_dir, exist_ok=True)
load_options = gw.EmailLoadOptions()
with gw.Watermarker("message.msg", load_options) as watermarker:
content = watermarker.get_content(gwc_email.EmailContent)
for attachment in content.attachments:
print("Name:", attachment.name)
print("File format:", attachment.get_document_info().file_type)
with open(os.path.join(output_dir, attachment.name), "wb") as f:
f.write(attachment.content)
import groupdocs.watermark as gw
import groupdocs.watermark.contents.email as gwc_email
from groupdocs.watermark.common import FileType
load_options = gw.EmailLoadOptions()
with gw.Watermarker("message.msg", load_options) as watermarker:
content = watermarker.get_content(gwc_email.EmailContent)
for i in range(content.attachments.count - 1, -1, -1):
attachment = content.attachments[i]
if ("sample" in attachment.name) and (attachment.get_document_info().file_type == FileType.DOCX):
content.attachments.remove_at(i)
watermarker.save("message.msg")
import groupdocs.watermark as gw
import groupdocs.watermark.contents.email as gwc_email
load_options = gw.EmailLoadOptions()
with gw.Watermarker("message.msg", load_options) as watermarker:
content = watermarker.get_content(gwc_email.EmailContent)
with open("sample.msg", "rb") as f:
content.attachments.add(f.read(), "sample.msg")
watermarker.save("message.msg")
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.