'How to add signature to powershell code creating new mail?

I want signatures to show up when creating new message as they do with Ctrl+N? Here is my code:

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.Subject = "data for Subject"
$Mail.Body ="Example of body..."
$Mail.Signature = "Primary"
$inspector = $mail.GetInspector
$inspector.Display()


Solution 1:[1]

You could refer to the below code:

    $Signature = "`n`nBest Regards,`nYourName`[email protected]"
    $Mail.Body = "Si comunica che i pacchetti harvest $esito.`nSi rimanda alle verifiche del caso `nSaluti$Signature"

For more information, Please refer to this link:

Powershell email signature

Solution 2:[2]

The signature is added when Display is called as long as the message body is unmodified. This means you must call Display first, and then merge your data with the body that the message has at this moment.

Also keep in mind that to keep the signature formatting, you must use the HTMLBody property rather than plain text Body. And you cannot simply concatenate two HTML strings - they must be merged.

If using Redemption (I am its author) is an option, it exposes RDOSignature.ApplyTo method, which allows to insert signature into an existing message.

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 Alina Li
Solution 2