Brian Scott
Brian Scott

Reputation: 9361

How do I set Outlook extended properties on an email in C#?

I have currently written code to send an email in C# using the usual SMTPClient and MailMessage objects.

My new requirement is that the email being sent should have "permissions" set as if the user was sending the email via Outloook and using the option from the ribbon toolbar. The permission to be set is the "Do Not Forward" option.

The option I wish to emulate when sending the email is accessed here;

"Do Not Forward" Option

Can anyone please supply some sample .Net code to achieve this or else provide me with a good code reference online?

Thanks in advance, Brian.

Upvotes: 4

Views: 2750

Answers (2)

Matt Weber
Matt Weber

Reputation: 756

First of all, I am unaware as to how one might be able to set IRM (Information Rights Management) permissions using only a standard SMTP message (MailMessage). IRM permissions, I believe, are completely Outlook/Exchange-centric, and lack any sort of representation in the SMTP standard.

The only way you're going to be able to enable that permission is through the Outlook Object Model via the Outlook Interop assemblies. IamStalker above me recommended Redemption, which, while 99% of the time is the correct answer for everything Outlook-related, is not the way to go for this particular problem. Because IRM (as far as I know) has no representation in MAPI, Redemption wouldn't be much help here; I don't believe I've ever seen an IRM-related property on Redemption's object model.

You'll most likely be interested in the Permission property exposed by the MailItem object type. It appears that in order to programmatically turn on the "Do Not Forward" option, you will want to set the value of that property to OlPermission.olDoNotForward.

There is another IRM-related property (PermissionTemplateGuid), but it appears that you can leave this as an empty string since you are using a built-in "permission".

I would assume then that all other IRM-related settings are provided to Outlook through the user's Outlook profile.

Good luck!

Upvotes: 5

hackp0int
hackp0int

Reputation: 4161

Hello Brian I have only one suggestion "Redemption"! I have used it and it's awesome it's very easy to implement the owner Dima is very nice person he helps alot.

PS: It's not free but worth every penny.

Upvotes: 1

Related Questions