'How to set classification of an email automatically?

I have the following powershell script:

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.Subject = "Hello"
$Mail.Body ="World"
$Mail.Send()

But when I execute it I have to select classification of the email manually: there appears a TITUS pop up with a the "Select Classification" title select box containing the following items: Public, For Internal Use Only and Private. I have to select an item and click "OK", after that the email is sent.

The script is supposed to be a job that gets run on schedule, so I don't want to interact with the script at all.

I have already walked through the whole msdn page of MailItem but I didn't come across anything similar to Classificaiton. What did I miss?

I am not an administrator of the server, so I don't have access to change anything.

PS: I selected the C# tag just because C# has the same API to interact with Outlook



Solution 1:[1]

Firstly, Outlook, just like any other Office app, is not designed to be used in unattended scenarios. It can and will display modal prompts out of the blue.

Secondly, to send a message, you can use straight SMTP, EWS, Extended MAPI (C++ or Delphi only), or Redemption (I am its author - its RDO family of objects wraps Extended MAPI and can be accessed for many language).

In your particular case, it sure looks like a custom third-party addin displaying a dialog box.

Solution 2:[2]

The mail object is not able to set the classification of the email object. If you pipe the object to Get-Member, you will see that there is no changeable property for the classification and/or a method to change it. You can find this by running the following command:

$Mail | Get-Member

Additionally, if you look at the list of properties there is not one that looks related to classification.

$Mail | Format-List

This blog post will probably help you, but it seems more complex than the solution you're looking for. This one utilizes Exchange instead of the Outlook client.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2