Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ public sealed class SendMailMessage : PSCmdlet
/// <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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down