TransWikia.com

Email draft - add recipients -Powershell

Stack Overflow Asked by Konstantinos V on November 7, 2021

running the following

$ol = New-Object -comObject Outlook.Application

$mail = $ol.CreateItem(0)



$mail.to.add("[email protected]")

$mail.Subject = "subject"

$mail.Body = "body"


$mail.save()

receiving:

You cannot call a method on a null-valued expression.

    At line:x char:x
+   $mail.to.add("[email protected]")
+   ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

  [1]: https://i.stack.imgur.com/TqAN9.png

One Answer

The To property of $mail seems to be a string so you should assign the recipient to it directly:

$mail.to = "[email protected]"

There is also the Recipients property which can be used to add multiple recipients.

Answered by JonC on November 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP