Forum Discussion

DFOTA's avatar
DFOTA
Copper Contributor
Apr 10, 2025

.Net mail message, PowerShell and Microsoft Purview Infrmation Protection

I have a PowerShell script that using the .net mail message to send emails. We want to restrict some of those emails to a certain sensitivity (we call it classification) and restrict it to only internal users (which this label does when sending via Outlook).

I have looked at a number of ways to do this but haven't come up with anything that works. Here are the issues:

The smtp server is NOT in Office 365.
The PowerShell window is opened as an admin account so using an Outlook interface might not work.
Currently, I have it set to send remotly (A session is created with the server that is whitelisted and it actually sends the message).

Any information would be of great assistance.

2 Replies

  • Bart_Pasmans's avatar
    Bart_Pasmans
    Copper Contributor

    If the SMTP server is not in O365 (but for instance on-premises with Exchange)

     

    What you could do is:

    • Add a custom header to your mail message
    • Configure the SMTP server to check the custom header and act accordingly on this

    For instance add header "X-ClassificationLabel" give it value "InternalOnly" or something. And apply the business logic on the SMTP to for instance prevent forwarding out of the organization.

     

    Is this something you are searching for?

  • https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.users.actions/send-mgusermail?view=graph-powershell-1.0

    Using Send-MgUsermail gives you more options to label emails. Have you checked that already?

Resources