Trying to Send IRM Encrypted Email But Body Of Email Is Blank

Copper Contributor
0

I am writing a script that will open an encrypted Outlook Template File to send and encrypted email. However, the body of the email is not popluating. Code below. Any help would be appreciated.

    $outlook = New-Object -ComObject outlook.application
    $Mail=$outlook.CreateItemFromTemplate(“C:\Users$env:UserName\AppData\
    Roaming\Microsoft\Templates\Encrypted.oft”)
    $Mail.SentOnBehalfOfName = “UnattendedEmailAddress”
    $Mail.To =“VendorEmailAddress”
    $Mail.CC = “HelpDeskEmailAddress”
    $Mail.Subject = “User With The Email $Vendor Was Not Found”
    $Mail.Body = ‘Please Double Check The Vendors Email Address And Then Enter It Again’
    $Mail.save()
    $inspector=$Mail.getinspector
    $inspector.display()
    #$Mail.Send()
Email.JPG

7 Replies

@DabearMDF58 

 

Hi, Matthew.

 

I can't see enough of your screenshot to confirm which message composition mode is your default, however, if it happens to be HTML (it will display at the end of the window title as shown in the example below) then you need to populate the HTMLBody property, not the Body property - per your current example.

 

LainRobertson_0-1712186093215.png

 

 

Cheers,

Lain

Hey Lain,
I have tried both properties and then both come up blank.

@DabearMDF58 

 

Did you assign HTML content to that attribute?

 

$Mail.HTMLBody = "<html><body>Please Double Check The Vendors Email Address And Then Enter It Again</body></html>";

 

Cheers,

Lain

@LainRobertson

Yeah I tried that.  I even used ConvertTo-Html and set that as the Body and piped it to a variable and then added the variable to the htmlbody property.

@DabearMDF58 

 

Odd.

 

I finally got a few minutes to test and it checks out for me.

 

Script

 

$outlook = New-Object -ComObject outlook.application

$Vendor = "Nobody's Home Furniture";

$Mail = $outlook.CreateItemFromTemplate("D:\Data\Temp\Forum\Forum.oft");
$Mail.SentOnBehalfOfName = "lain.robertson";
$Mail.To = "email address removed for privacy reasons";
$Mail.CC = "email address removed for privacy reasons";
$Mail.Subject = "User With The Email $Vendor Was Not Found";
$Mail.HTMLBody = "<html><body>Please Double Check The Vendors Email Address And Then Enter It Again</body></html>";

$inspector=$Mail.getinspector;
$inspector.display();

 

 

 

Output

LainRobertson_6-1712202248574.png

 

 

 

Edited to resolve issues with smart quotes in all strings from the original script.

 

Cheers,

Lain

@DabearMDF58 

 

Two random quick mentions as afterthoughts:

 

  1. Your code sample features smart quotes around the HTMLBody string value, which may be a non-issue if they're only in this web content (but they would be an issue if they're somehow really in your PowerShell code);
  2. If your template is HTML-based and has already got a value for HTMLBody, then you'd want to be sure that the text you're adding either fully replaces the existing value or that you're inserting it correctly into the existing string block, as if things like tags don't match or free text exists outside of allowable boundaries, it won't render.

 

But again, these are just afterthoughts and may have no relevance to your test at all.

 

Cheers,

Lain

As you have shown and in my own testing, I can get text to show in a non-IRM flagged email. However, I am trying to use a IRM flagged email.