kmwoley / restic-windows-backup

Powershell scripts to run Restic backups on Windows
MIT License
330 stars 68 forks source link

Replace deprecated Send-MailMessage cmdlet with recommended Send-Mail… #101

Open ckewinjones opened 2 months ago

ckewinjones commented 2 months ago

Email functionality of backup.ps1 fails on Windows 11 23H2. Send-MailMessage has been deprecated in favor of the Send-MailKitMessage module from PSGallery.

In this PR:

See issue 100 (Email sent from backup task fails on Windows 11)

ilium007 commented 2 months ago

Is this backwards compatible with Windows 10 Powershell versions?

daniel-rikowski commented 2 months ago

In case it helps:

I tested Send-MailKitMessage in the stock version of Powershell of Windows 10 (i.e. the one in C:\Windows\System32\WindowsPowerShell\v1.0)

Name                           Value                                                                                                                                     
----                           -----                                                                                                                                     
PSVersion                      5.1.19041.4780                                                                                                                            
PSEdition                      Desktop                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                   
BuildVersion                   10.0.19041.4780                                                                                                                           
CLRVersion                     4.0.30319.42000                                                                                                                           
WSManStackVersion              3.0                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                       
SerializationVersion           1.1.0.1  

I got a warning, that NuGet needs to be installed before, which I only needed to confirm. Then I got a warning that PSGallery is not trusted.

Other than that, everything succeeded.

Also the Changelog of Send-MailKitMessage suggests, that it is intended to work with many Powershell versions. (https://github.com/austineric/Send-MailKitMessage?tab=readme-ov-file#releases https://github.com/austineric/Send-MailKitMessage/commit/929b53ba767b21376ab35944d593859e728b9c78)