Skip to content

Should Send-MailMessage be marked obsolete #11975

Closed

Description

@FireInWinter

Version: PowerShell 7.0rc3
OS: AWS Linux

Currently Send-MailMessage is marked obsolete, but I don't think it should be. The API behind it should be replaced eventually, but the site that gives the reasons why it should be used, also include a reason what it would still be useful for.

https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md

It's great for one off emails from tools, but doesn't scale to modern requirements of the protocol.

My reasoning is that the majority of use of Send-MailMessage is exactly the "one off emails from tools" they mention. If someone has some statistics, that would be great, but my guess is that 95% of use of Send-MailMessage would fall under that category. It would be obsolete if someone is using it for sending millions of emails, but I doubt if there are many people doing that.

I would suggest having it marked in some way in the source code, but let's not bug users about a problem that isn't a real problem.

Activity

  1. added
    Issue-Enhancement
    on Feb 28, 2020
  2. doctordns commented on Feb 29, 2020

    @doctordns
    Collaborator

    For simple administrative things, like emailing the results of a PowerShell script run via the Task Scheduler, this is an excellent cmdlet. It does what it needs to - and sends mail. I accept the argument that it may not support the latest and greatest protocols nor is it scalable. But for simple one-off tasks, it works.

    If it is to be removed, then there should be a replacement that enables a PowerShell script to send an email.

  3. vexx32 commented on Feb 29, 2020

    @vexx32
    Collaborator

    Agreed. I think the deprecation notice should be prominently displayed in the help summary and a brief comment about it including a link to the .NET Core deprecation notice for the related API should be included in the full help description and/or related links/notes.

    Having it always emit a warning is primarily an annoyance to most folks who're going to be using it regardless, and doesn't add a significant degree of value here.

  4. doctordns commented on Mar 1, 2020

    @doctordns
    Collaborator

    If any cmdlet has to issue warning message then it should be actionable. What action can the user take? Just saying this is 'old' is not at all helpful.

    What is the alternative to this cmdlet? If an IT pro wants to send a simple email how can they do so?

  5. user8446 commented on Aug 28, 2020

    @user8446

    The replacement is MailKit. If you want this wrapped up in a cmdlet, use Mailozaurr module available in the PS Gallery

  6. martin9700 commented on Aug 28, 2020

    @martin9700

    Why would you obsolete the cmdlet? It just seems like an odd approach to the problem. Instead of obsoleting one of the most used cmdlet's in PowerShell I have a weird suggestion: Why not just fix it?

    Start a branch, re-write it from the ground up. Wouldn't the fixes mostly be in the background? On the surface at least, seems like you might not even blow up every script that uses it 🤷‍♂️

  7. user8446 commented on Aug 28, 2020

    @user8446

    I agree. Apparently the PS committee hasn't completely decided to not upgrade it, just wants to see it in in a separate module first and will decide later. See: #10246

  8. EchoApeiron commented on Oct 27, 2020

    @EchoApeiron

    There is another alternative native to Powershell, but requires using .NET objects. Credit to these writers I used this to store my credentials securely, but this is a better method and I provide a code snippet as well to help:

    Powershell: How to encrypt and store credentials securely for use with automation scripts

    $userName = "user@domain.com"
    $password = Get-Content .\encrypted_password.txt | ConvertTo-SecureString
    $credentials = New-Object System.Management.Automation.PsCredential($userName, $password)
    # SMTP Variables 
    $emailFrom = "info@domain.com"
    $emailTo = "user@remote-domain.com"
    $subject = "Test"
    $body = "Some test message." 
    $SMTPServer = "smtp.domain.com"
    $SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = $credentials
    $SMTPClient.Send($emailFrom, $emailTo, $subject, $body)
    
  9. MWRobertson commented on Nov 19, 2020

    @MWRobertson

    Dion Pezzimenti (@EchoApeiron) , I had the same thought but just confirmed with someone on the PowerShell team that the Net.Mail.SmtpClient object is what's running behind the scenes of Send-MailMessage, and that is what is actually marked for deprecation, so this workaround will also be obsolete.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. added
    Resolution-No Activity
    on Nov 16, 2023
  14. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions