Send-MailMessage: Update all parameters to support 'ValueFromPipelineByPropertyName'. (#6911)
This commit is contained in:
parent
bacda46941
commit
7628f8819d
|
@ -24,7 +24,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// If the filename specified can not be found, then the relevant error
|
||||
/// message should be thrown.
|
||||
/// </summary>
|
||||
[Parameter(ValueFromPipeline = true)]
|
||||
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[Alias("PsPath")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
|
@ -42,7 +42,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// Specifies the address collection that contains the
|
||||
/// blind carbon copy (BCC) recipients for the e-mail message.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public String[] Bcc
|
||||
|
@ -58,7 +58,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies the body (content) of the message
|
||||
/// </summary>
|
||||
[Parameter(Position = 2)]
|
||||
[Parameter(Position = 2, ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public String Body
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies a value indicating whether the mail message body is in Html.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("BAH")]
|
||||
public SwitchParameter BodyAsHtml
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// Specifies the encoding used for the content of the body and also the subject.
|
||||
/// This is set to ASCII to ensure there are no problems with any email server
|
||||
/// </summary>
|
||||
[Parameter()]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("BE")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[ArgumentCompletions(
|
||||
|
@ -110,7 +110,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// Specifies the address collection that contains the
|
||||
/// carbon copy (CC) recipients for the e-mail message.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Cc")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
|
@ -128,7 +128,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// Specifies the delivery notifications options for the e-mail message. The various
|
||||
/// option available for this parameter are None, OnSuccess, OnFailure, Delay and Never
|
||||
/// </summary>
|
||||
[Parameter()]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("DNO")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public DeliveryNotificationOptions DeliveryNotificationOption
|
||||
|
@ -145,7 +145,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// Specifies the from address for this e-mail message. The default value for
|
||||
/// this parameter is the email address of the currently logged on user
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true)]
|
||||
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public String From
|
||||
{
|
||||
|
@ -162,7 +162,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// to the Powershell variable PSEmailServer,if this host can not reached an appropriate error
|
||||
/// message will be displayed.
|
||||
/// </summary>
|
||||
[Parameter(Position = 3)]
|
||||
[Parameter(Position = 3, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("ComputerName")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public String SmtpServer
|
||||
|
@ -178,7 +178,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies the priority of the email message. The valid values for this are Normal, High and Low
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public MailPriority Priority
|
||||
{
|
||||
|
@ -193,7 +193,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies the subject of the email message.
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 1)]
|
||||
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("sub")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public String Subject
|
||||
|
@ -209,7 +209,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies the To address for this e-mail message.
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 0)]
|
||||
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public String[] To
|
||||
|
@ -225,7 +225,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies the credential for this e-mail message.
|
||||
/// </summary>
|
||||
[Parameter()]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[Credential]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public PSCredential Credential
|
||||
|
@ -241,7 +241,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <summary>
|
||||
/// Specifies if Secured layer is required or not
|
||||
/// </summary>
|
||||
[Parameter()]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
public SwitchParameter UseSsl
|
||||
{
|
||||
get { return _usessl; }
|
||||
|
@ -258,7 +258,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
/// <remarks>
|
||||
/// Value must be greater than zero.
|
||||
/// </remarks>
|
||||
[Parameter()]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateRange(0, Int32.MaxValue)]
|
||||
public int Port
|
||||
{
|
||||
|
@ -389,7 +389,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
this.ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
if (0 == _port)
|
||||
if (_port == 0)
|
||||
{
|
||||
_mSmtpClient = new SmtpClient(_smtpserver);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
|
|||
return $rv
|
||||
}
|
||||
|
||||
$PesterArgs = @{ Name = "Can send mail message from user to self"}
|
||||
$PesterArgs = @{Name = ""}
|
||||
$alreadyHasMail = $true
|
||||
|
||||
if (-not $IsLinux)
|
||||
|
@ -126,14 +126,18 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
|
|||
}
|
||||
$alreadyHasMail = $false
|
||||
}
|
||||
AfterAll {
|
||||
|
||||
AfterEach {
|
||||
if (-not $alreadyHasMail)
|
||||
{
|
||||
Set-Content -Value "" -Path $mailBox -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
It @PesterArgs {
|
||||
$ItArgs = $PesterArgs.Clone()
|
||||
$ItArgs['Name'] = "Can send mail message from user to self " + $ItArgs['Name']
|
||||
|
||||
It @ItArgs {
|
||||
$body = "Greetings from me."
|
||||
$subject = "Test message"
|
||||
Send-MailMessage -To $address -From $address -Subject $subject -Body $body -SmtpServer 127.0.0.1
|
||||
|
@ -146,4 +150,22 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
|
|||
$mail.Body.Count | Should -BeExactly 1
|
||||
$mail.Body[0] | Should -BeExactly $body
|
||||
}
|
||||
|
||||
$ItArgs = $PesterArgs.Clone()
|
||||
$ItArgs['Name'] = "Can send mail message from user to self using pipeline " + $ItArgs['Name']
|
||||
|
||||
It @ItArgs {
|
||||
$body = "Greetings from me."
|
||||
$subject = "Test message"
|
||||
$object = [PSCustomObject]@{"To" = $address; "From" = $address; "Subject" = $subject; "Body" = $body; $SmtpServer = '127.0.0.1'}
|
||||
$object | Send-MailMessage
|
||||
Test-Path -Path $mailBox | Should -BeTrue
|
||||
$mail = read-mail $mailBox
|
||||
$mail.From | Should -BeExactly $address
|
||||
$mail.To.Count | Should -BeExactly 1
|
||||
$mail.To[0] | Should -BeExactly $address
|
||||
$mail.Subject | Should -BeExactly $subject
|
||||
$mail.Body.Count | Should -BeExactly 1
|
||||
$mail.Body[0] | Should -BeExactly $body
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue