mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Made -Subject parameter of SendMail command no longer mandatory. (#8961)
This commit is contained in:
@@ -117,9 +117,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Gets or sets the subject of the email message.
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Mandatory = false, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("sub")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public string Subject { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -61,6 +61,16 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix {
|
||||
SmtpServer = "127.0.0.1"
|
||||
}
|
||||
}
|
||||
@{
|
||||
Name = "with No Subject"
|
||||
InputObject = @{
|
||||
From = "user01@example.com"
|
||||
To = "user02@example.com"
|
||||
ReplyTo = "noreply@example.com"
|
||||
Body = "Body $(Get-Date)"
|
||||
SmtpServer = "127.0.0.1"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
It "Can send mail message using named parameters <Name>" -TestCases $testCases {
|
||||
@@ -78,7 +88,9 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix {
|
||||
$mail.Headers["From"] | Should -BeExactly $InputObject.From
|
||||
$mail.Headers["To"] | Should -BeExactly $InputObject.To
|
||||
$mail.Headers["Reply-To"] | Should -BeExactly $InputObject.ReplyTo
|
||||
$mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject
|
||||
If ($InputObject.Subject -ne $null) {
|
||||
$mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject
|
||||
}
|
||||
|
||||
$mail.MessageParts.Count | Should -BeExactly 1
|
||||
$mail.MessageParts[0].BodyData | Should -BeExactly $InputObject.Body
|
||||
@@ -101,7 +113,9 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix {
|
||||
$mail.Headers["From"] | Should -BeExactly $InputObject.From
|
||||
$mail.Headers["To"] | Should -BeExactly $InputObject.To
|
||||
$mail.Headers["Reply-To"] | Should -BeExactly $InputObject.ReplyTo
|
||||
$mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject
|
||||
If ($InputObject.Subject -ne $null) {
|
||||
$mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject
|
||||
}
|
||||
|
||||
$mail.MessageParts.Count | Should -BeExactly 1
|
||||
$mail.MessageParts[0].BodyData | Should -BeExactly $InputObject.Body
|
||||
|
||||
Reference in New Issue
Block a user