I am unable to add watermark to .msg file. I am using watermark sdk version 20.5. Attached file for reference. Please rename .pdf to .msg extension since I can’t upload .msg file directly in this forum.
sample.pdf (24 KB)
This issue is reproduced at our end. Hence, we’ve logged it in our internal issue tracking system with ID WATERMARKJAVA-105. You’ll be notified in case of any update.
Hello,
Thank you for the sample file.
This is not a defect — adding a watermark directly to an email message is not supported by design, and the behaviour is the same in both GroupDocs.Watermark for Java and for .NET. An email message has no page or canvas to place a watermark on, so Watermarker.add() on a .msg file intentionally throws NotSupportedException (“Specified method is not supported.”). This will happen with any MSG file, not just the attached one.
What you can do with MSG files:
- Attachments — add watermarks to the documents and images attached to the message, via
EmailContent.getAttachments(). This is the usual way to watermark email content. - Embedded objects — via
EmailContent.getEmbeddedObjects(). - Subject and body — can be modified directly with
setSubject(),setBody()andsetHtmlBody().
A short example for attachments:
Watermarker watermarker = new Watermarker("sample.msg");
EmailContent content = watermarker.getContent(EmailContent.class);
for (EmailAttachment attachment : content.getAttachments()) {
if (attachment.getDocumentInfo().getFileType().isSupported()) {
Watermarker attachmentWatermarker = attachment.getWatermarker();
attachmentWatermarker.add(new TextWatermark("top secret", new Font("Arial", 12)));
attachmentWatermarker.close();
}
}
watermarker.save("output.msg");
watermarker.close();
Please note that the file you attached contains only text and has no attachments, so there is nothing in it that a watermark could be applied to. If you could tell us what result you expect for such a message — for example, marking the message body text — we will be happy to advise on the best approach.
Also, a small note on your snippet: new TextWatermark("top secret", null) passes null as the font. Please pass a valid Font instance, otherwise you may hit a separate error once you switch to the attachment-based approach.
Best regards