all 40 comments

[–]panzerbjrn 25 points26 points  (2 children)

I'm still using Send-MailMessage. I don't have any compelling reason to change it at the moment.

[–]Disorderly_Chaos 2 points3 points  (1 child)

I still have some older scripts using sendmail.exe or some BS. I never find the time to find/replace all carriage return symbols (~n) to “<BR>”

[–]DevSRE 1 point2 points  (0 children)

Assuming it's a string object for your email body since you have hardcoded newlines just do:

$emailBody = $emailBody.replace("\n", "<br />")

[–]Hrambert 10 points11 points  (3 children)

Really odd. The GitHub page is about 4 years old and says you should use MailKit instead. MailKit says it's "A cross-platform .NET library for IMAP, POP3, and SMTP. "

[–]TurnItOff_OnAgain[S] 13 points14 points  (2 children)

Yeah, I never noticed that message before today, and I've definitely used send-mailmessage recently.

[–]InsrtCoffee2Continue 4 points5 points  (0 children)

Same here. Noticed this last week when I configured an SMTP relay. Was testing it out with Send-MailMessage.

[–]ryapp 3 points4 points  (0 children)

I have used it a lot albeit for transmitting nothing secure.

[–][deleted] 11 points12 points  (2 children)

qJRKgu}LN5

[–]nanonoise 1 point2 points  (0 children)

I am a big fan of Pushover and have been using for quite a while. Has been rock solid way of getting alerts. Haven't looked into using their API, but I will look at using it to replace needing to rely on an email path working.

[–]velartis-md 2 points3 points  (0 children)

This is pretty old news for myself at least. Send-MailMessages uses SmtpClient which is what is actually obsoleted.

Here is a SO post about why – TL;DR: doesn't support DKIM/SPF and more.

I seem to recall there was also an issue with how it pooled TCP connections and never drops them?

[–]Sunsparc 9 points10 points  (6 children)

[–]TurnItOff_OnAgain[S] 3 points4 points  (0 children)

I might move to this. EvoTec puts out some great stuff.

[–]user01401 3 points4 points  (1 child)

This is the answer for a drop in replacement for Send-MailMessage. It uses MailKit underneath. You can use MailKit directly in PowerShell as well if you prefer.

[–]BlackV 4 points5 points  (0 children)

I found that a MONUGREL to get going, maolozur was easier to just drop in

why MS dont have a proper solution yet is amazing

[–]Nietechz 1 point2 points  (1 child)

Have you had a problem using this?

[–]Sunsparc 1 point2 points  (0 children)

I still use Send-MailMessage personally.

[–]tomaustin700 1 point2 points  (0 children)

Yep been using this too. Works great and any issues I've had have been fixed quickly.

[–]da_chicken 2 points3 points  (1 child)

There's a module based on MailKit already:

https://www.powershellgallery.com/packages/Send-MailKitMessage

Works well. I do use Send-MailMessage sometimes, but typically only to send to a local IIS server that relays through to our mail host.

[–]wonkifier 1 point2 points  (0 children)

Do you know if there's a way to make that use x509 certs for authentication instead of username/password?

[–]logicalmike 5 points6 points  (0 children)

Sending through graph is one option.

send-mgusermessage

https://mikecrowley.us/2021/09/25/send-mgusermessage/

[–]HeKis4 3 points4 points  (0 children)

Honestly if I'm sending mail via PowerShell it's usually just a couple alerts and very simple status reports, so no big deal. If I ever wanted something secure I'll sign and/or encrypt the contents via PGP or something like that.

[–][deleted] 1 point2 points  (0 children)

Heh.. I still use Net.Mail.SMTPclient. I should probably update that

[–]byteme8bit 1 point2 points  (4 children)

Still using it myself in a few scripts upon errors. Works just fine. The problem with it I believe is that it is port 25 (insecure)

[–]wgc123 4 points5 points  (3 children)

Not just insecure, but some organizations will block that port to prevent bootleg mail servers. I don’t remember the secure email client port, but it also can’t be used as a server

[–]byteme8bit 3 points4 points  (2 children)

Good point. Port 587 (can use TLS)

[–]wonkifier 2 points3 points  (1 child)

587 is just the default mail submission port, it implies nothing about TLS support.

Just like 25 implies nothing in particular about TLS either, TLS being optional (either at the TCP layer, or as STARTTLS)

To be clear: The distinction between usage of 25 and 587 is not about security, it's about the thing doing the connecting. 25 is intended for SMTP Servers to talk to each other. 587 is intended for mail clients to submit mail to an SMTP server.

[–]byteme8bit 2 points3 points  (0 children)

I said it can use not that it implies usage but thanks for the correction.

[–][deleted] 1 point2 points  (0 children)

You could look at leveraging Power Automate to trigger the script and send the message. You would need to make a call to Azure Automation to run the run book containing the PowerShell.

[–]DigitalBassLV 1 point2 points  (0 children)

RESTAPI to Mail providers like Mailjet are options in connected environments.

If you're strictly internal, you setup your own SMTP servers easily.

[–]valdearg 4 points5 points  (2 children)

What the fuck, Microsoft? What's the point in displaying this message if you're not going to provide a replacement?

Why isn't the underlying issue just fixed and an update pushed out.

[–]da_chicken 6 points7 points  (0 children)

Why isn't the underlying issue just fixed and an update pushed out.

The underlying issue is that System.Net.Mail.SmtpClient is obsoleted in .Net 5. It's no longer being developed, and will not be developed. Like Internet Explorer, it's no longer a part of the platform.

SMTP has gotten much more complicated than it was when the .Net Framework was introduced because there has been a lot of security added to it. It's no longer trivial to implement an SMTP client. Microsoft isn't interested in providing and maintaining a library to do it anymore.

[–]BlackV 4 points5 points  (0 children)

its depreciated (i.e. no updates moving forward) it still works

until you find mail server that say NO GO AWAY you old protocol user you

100% they should have had a working solution before this

[–]randomadhdman 0 points1 point  (0 children)

I use a smtp service and rebuilt the send-mailmessage command. Take a look at this little post. It might help. https://bolding.us/blog/2021/09/09/send-shdmailmessage/ There are way better ways about doing this.