Adding parameter "ReplyTo" to Send-MailMessage (#8727)
This commit is contained in:
parent
528b0992b2
commit
c935bce1ac
|
@ -108,6 +108,12 @@ namespace Microsoft.PowerShell.Commands
|
||||||
[ValidateNotNullOrEmpty]
|
[ValidateNotNullOrEmpty]
|
||||||
public MailPriority Priority { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the subject of the email message.
|
/// Gets or sets the subject of the email message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -187,6 +193,11 @@ namespace Microsoft.PowerShell.Commands
|
||||||
_mMailMessage.Bcc.Add(new MailAddress(strEmailAddress));
|
_mMailMessage.Bcc.Add(new MailAddress(strEmailAddress));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "replyTo":
|
||||||
|
{
|
||||||
|
_mMailMessage.ReplyToList.Add(new MailAddress(strEmailAddress));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FormatException e)
|
catch (FormatException e)
|
||||||
|
@ -233,6 +244,12 @@ namespace Microsoft.PowerShell.Commands
|
||||||
AddAddressesToMailMessage(Cc, "cc");
|
AddAddressesToMailMessage(Cc, "cc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the Reply-To address of the mail message
|
||||||
|
if (ReplyTo != null)
|
||||||
|
{
|
||||||
|
AddAddressesToMailMessage(ReplyTo, "replyTo");
|
||||||
|
}
|
||||||
|
|
||||||
// Set the delivery notification
|
// Set the delivery notification
|
||||||
_mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOption;
|
_mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOption;
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,15 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
|
||||||
|
|
||||||
$rv.To += $line.Substring(4)
|
$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: "))
|
elseif ($line.StartsWith("Subject: "))
|
||||||
{
|
{
|
||||||
$rv.Subject = $line.Substring(9);
|
$rv.Subject = $line.Substring(9);
|
||||||
|
@ -140,12 +149,14 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
|
||||||
It @ItArgs {
|
It @ItArgs {
|
||||||
$body = "Greetings from me."
|
$body = "Greetings from me."
|
||||||
$subject = "Test message"
|
$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
|
Test-Path -Path $mailBox | Should -BeTrue
|
||||||
$mail = read-mail $mailBox
|
$mail = read-mail $mailBox
|
||||||
$mail.From | Should -BeExactly $address
|
$mail.From | Should -BeExactly $address
|
||||||
$mail.To.Count | Should -BeExactly 1
|
$mail.To.Count | Should -BeExactly 1
|
||||||
$mail.To[0] | Should -BeExactly $address
|
$mail.To[0] | Should -BeExactly $address
|
||||||
|
$mail.ReplyTo.Count | Should -BeExactly 1
|
||||||
|
$mail.ReplyTo[0] | Should -BeExactly $address
|
||||||
$mail.Subject | Should -BeExactly $subject
|
$mail.Subject | Should -BeExactly $subject
|
||||||
$mail.Body.Count | Should -BeExactly 1
|
$mail.Body.Count | Should -BeExactly 1
|
||||||
$mail.Body[0] | Should -BeExactly $body
|
$mail.Body[0] | Should -BeExactly $body
|
||||||
|
@ -157,13 +168,15 @@ Describe "Basic Send-MailMessage tests" -Tags CI {
|
||||||
It @ItArgs {
|
It @ItArgs {
|
||||||
$body = "Greetings from me again."
|
$body = "Greetings from me again."
|
||||||
$subject = "Second test message"
|
$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
|
$object | Send-MailMessage
|
||||||
Test-Path -Path $mailBox | Should -BeTrue
|
Test-Path -Path $mailBox | Should -BeTrue
|
||||||
$mail = read-mail $mailBox
|
$mail = read-mail $mailBox
|
||||||
$mail.From | Should -BeExactly $address
|
$mail.From | Should -BeExactly $address
|
||||||
$mail.To.Count | Should -BeExactly 1
|
$mail.To.Count | Should -BeExactly 1
|
||||||
$mail.To[0] | Should -BeExactly $address
|
$mail.To[0] | Should -BeExactly $address
|
||||||
|
$mail.ReplyTo.Count | Should -BeExactly 1
|
||||||
|
$mail.ReplyTo[0] | Should -BeExactly $address
|
||||||
$mail.Subject | Should -BeExactly $subject
|
$mail.Subject | Should -BeExactly $subject
|
||||||
$mail.Body.Count | Should -BeExactly 1
|
$mail.Body.Count | Should -BeExactly 1
|
||||||
$mail.Body[0] | Should -BeExactly $body
|
$mail.Body[0] | Should -BeExactly $body
|
||||||
|
|
Loading…
Reference in a new issue