Skip to content

Send-MailMessage $Subject Mandatory=$true #4043

@BitteringAgent

Description

@BitteringAgent

Not a bug, but a request for "Send-MailMessage" cmdlet

 $From = $email
    $To = $Number
    $Body = "Something"
    $Subject = $null
    $SMTPServer = "smtp.gmail.com"
    $SMTPPort = "587"
    Send-MailMessage -From $From -to $To -Subject $Subject `
        -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
    -Credential $Cred

RESULT:

Send-MailMessage : Cannot validate argument on parameter 'Subject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:8 char:52
+       -Body $Body -SmtpServer $SMTPServer -Subject $Subject -port $SM ...
+                                                    ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage

CAUSE:

[Parameter(Mandatory=$true, Position=1)]
        [Alias('sub')]
        [ValidateNotNullOrEmpty()]
        [string]
        ${Subject},

Emails do not require subjects to be present. However, in the Send-MailMessage cmdlet, the $subject parameter is set to "Mandatory=$true". Since an email does not require a subject, this should really be set to "$false".

I've created my own workaround this, but I feel that this should be changed since a subject is not imperative for an email to be sent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionFirst-Time-IssueEasy issues first time contributors can work on to learn about this projectHacktoberfestPotential candidate to participate in HacktoberfestIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions