The current implementation is processing parameters in BeginProcessing. While this works for parameters that are explicitly passed to the cmdlet, it fails for parameters that are populated form properties of the pipeline object because parameters are not set until the pipeline object is sent to ProcessRecord.
The logic for parameters bound from the pipleline needs to be moved to ProcessRecord.
Steps to reproduce
$object = [PSCustomObject]@{To = $address; From = $address; Subject = $subject; Body = $body; SmtpServer = '127.0.0.1'}
$object | Send-MailMessage
Expected behavior
The mail is sent.
Actual behavior
System.ArgumentNullException: Value cannot be null
Parameter name: address
The current implementation is processing parameters in BeginProcessing. While this works for parameters that are explicitly passed to the cmdlet, it fails for parameters that are populated form properties of the pipeline object because parameters are not set until the pipeline object is sent to ProcessRecord.
The logic for parameters bound from the pipleline needs to be moved to ProcessRecord.
Steps to reproduce
Expected behavior
The mail is sent.
Actual behavior
System.ArgumentNullException: Value cannot be null
Parameter name: address