diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs
index e77c1b6df..506715eb5 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs
@@ -108,6 +108,12 @@ namespace Microsoft.PowerShell.Commands
[ValidateNotNullOrEmpty]
public MailPriority Priority { get; set; }
+ ///
+ /// Gets or sets the Reply-To field for this e-mail message.
+ ///
+ [Parameter(ValueFromPipelineByPropertyName = true)]
+ public string[] ReplyTo { get; set; }
+
///
/// Gets or sets the subject of the email message.
///
@@ -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;
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1
index a1c68c521..5d8756006 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1
@@ -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