From c935bce1ac4a3130559c9a141bb5846e0c61f84c Mon Sep 17 00:00:00 2001 From: Joshua T Date: Wed, 30 Jan 2019 18:33:15 -0600 Subject: [PATCH] Adding parameter "ReplyTo" to Send-MailMessage (#8727) --- .../commands/utility/Send-MailMessage.cs | 17 +++++++++++++++++ .../Send-MailMessage.Tests.ps1 | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) 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