Adding parameter "ReplyTo" to Send-MailMessage (#8727)

This commit is contained in:
Joshua T 2019-01-30 18:33:15 -06:00 committed by Andrew
parent 528b0992b2
commit c935bce1ac
2 changed files with 32 additions and 2 deletions

View File

@ -108,6 +108,12 @@ namespace Microsoft.PowerShell.Commands
[ValidateNotNullOrEmpty]
public MailPriority Priority { get; set; }
/// <summary>
/// Gets or sets the Reply-To field for this e-mail message.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
public string[] ReplyTo { get; set; }
/// <summary>
/// Gets or sets the subject of the email message.
/// </summary>
@ -187,6 +193,11 @@ namespace Microsoft.PowerShell.Commands
_mMailMessage.Bcc.Add(new MailAddress(strEmailAddress));
break;
}
case "replyTo":
{
_mMailMessage.ReplyToList.Add(new MailAddress(strEmailAddress));
break;
}
}
}
catch (FormatException e)
@ -233,6 +244,12 @@ namespace Microsoft.PowerShell.Commands
AddAddressesToMailMessage(Cc, "cc");
}
// Set the Reply-To address of the mail message
if (ReplyTo != null)
{
AddAddressesToMailMessage(ReplyTo, "replyTo");
}
// Set the delivery notification
_mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOption;

View File

@ -57,6 +57,15 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
$rv.To += $line.Substring(4)
}
elseif ($line.StartsWith("Reply-To: "))
{
if ($null -eq $rv.ReplyTo)
{
$rv.ReplyTo = @()
}
$rv.ReplyTo += $line.Substring(10)
}
elseif ($line.StartsWith("Subject: "))
{
$rv.Subject = $line.Substring(9);
@ -140,12 +149,14 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
It @ItArgs {
$body = "Greetings from me."
$subject = "Test message"
Send-MailMessage -To $address -From $address -Subject $subject -Body $body -SmtpServer 127.0.0.1
Send-MailMessage -To $address -From $address -ReplyTo $address -Subject $subject -Body $body -SmtpServer 127.0.0.1
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.ReplyTo.Count | Should -BeExactly 1
$mail.ReplyTo[0] | Should -BeExactly $address
$mail.Subject | Should -BeExactly $subject
$mail.Body.Count | Should -BeExactly 1
$mail.Body[0] | Should -BeExactly $body
@ -157,13 +168,15 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
It @ItArgs {
$body = "Greetings from me again."
$subject = "Second test message"
$object = [PSCustomObject]@{To = $address; From = $address; Subject = $subject; Body = $body; SmtpServer = '127.0.0.1'}
$object = [PSCustomObject]@{To = $address; From = $address; ReplyTo = $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.ReplyTo.Count | Should -BeExactly 1
$mail.ReplyTo[0] | Should -BeExactly $address
$mail.Subject | Should -BeExactly $subject
$mail.Body.Count | Should -BeExactly 1
$mail.Body[0] | Should -BeExactly $body