austineric / Send-MailKitMessage

A replacement for PowerShell's obsolete Send-MailMessage implementing the Microsoft-recommended MailKit library.
https://www.powershellgallery.com/packages/Send-MailKitMessage
MIT License
47 stars 6 forks source link

Powershell 5.1 #30

Closed MihaIvan closed 2 years ago

MihaIvan commented 2 years ago

I have a requirement to use a Powershell module that will only run on Powershell 5.1. I have used Send-MailkitMessage successfully in Powershell 7, but have not been able to get it to work in PS 5.1. I noticed 3.2 said support for Windows Powershell which I think is what I need, but I cannot get it to work.

When I use the regular install-module, I get version 3.1, and it gets an error on line 85 of Send-Mailkitmessage.psm1: $Client.Connect($SMTPServer, $Port, ($UseSecureConnectionIfAvailable.IsPresent ? [MailKit.Security.SecureSocketOptions]::Auto : [MailKit.Security.SecureSocketOptions]::None))

It chokes on the question mark. I tried using the Install-module with the -Allowprerelease option, but it tells me that the option is invalid. Can you tell me how to get this done, or how to fix the problem statement so it will work in version 3.1?

austineric commented 2 years ago

Hi @MihaIvan, Yes version 3.1 is going to fail for you since it doesn't support Windows PowerShell. We need to get the prerelease version working.

Here's what I see when I use Windows PowerShell: image

Can you imitate the screenshot and upload one of your own if it fails?

MihaIvan commented 2 years ago

PS C:\Users\MikeL> $PSVersionTable

Name Value


PSVersion 5.1.19041.1320 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.1320 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

PS C:\Users\MikeL> install-module -name "Send-MailKitMessage" -AllowPrerelease Install-Module : A parameter cannot be found that matches parameter name 'AllowPrerelease'. At line:1 char:44

PS C:\Users\MikeL>

austineric commented 2 years ago

Hi @MihaIvan, Like in #28 that isn't a Send-MailKit error message, that's a PowerShell error message.

If you Google "Install-Module : A parameter cannot be found that matches parameter name 'AllowPrerelease'." you will find solutions that relate to updating PowerShell Get, ie Update-Module PowerShellGet -Force.

Try working in that direction and if you have a Send-MailKitMessage problem open another issue.