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
44 stars 5 forks source link

Slew of errors on `Import-Module` #26

Closed astrohart closed 2 years ago

astrohart commented 2 years ago

Hi,

I am running PowerShell version as given below:

PS C:\Windows\system32> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1237

I ran the following PowerShell script on a fresh install of Windows:

param (
    [switch]$Silent
)
if (-Not $Silent) { Write-Host "Setting ProgressPreference to SilentlyContinue..." }
if (-Not $Silent) { Write-Host "Setting the ProgressPreference to 'SilentlyContinue'..." }
$ProgressPreference = 'SilentlyContinue'
if (-Not $Silent) { Write-Host "Setting the execution policy..." }
Set-ExecutionPolicy RemoteSigned 2>&1 | out-null
if (-Not $Silent) { Write-Host "Configuring the security for ServicePointManager to use at least TLS 1.2..." }
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (-Not $Silent) { Write-Host "Configuring the system to use strong cryptography..." }
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord 2>&1 | out-null
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord 2>&1 | out-null
if (-Not $Silent) { Write-Host "Installing the PowerShell PackageManagement NuGet provider..." }
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force 2>&1 | out-null
if (-Not $Silent) { Write-Host "Setting the PSGallery as a trusted repository..." }
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted 2>&1 | out-null
if (-Not $Silent) { Write-Host "Setting the NuGet package source as trusted..." }
Register-PackageSource -Name NuGet -Location 'https://www.nuget.org/api/v2' -ProviderName 'NuGet' -Trust 2>&1 | out-null
if (-Not $Silent) { Write-Host "Installing MimeKit NuGet package..." }
Install-Package -Name 'MimeKit' -Source "https://www.nuget.org/api/v2" -SkipDependencies -Force 2>&1 | out-null
if (-Not $Silent) { Write-Host "Installing MailKit NuGet package..." }
Install-Package -Name 'MailKit' -Source "https://www.nuget.org/api/v2" 2>&1 | out-null
Install-Module -Name Send-MailKitMessage

Then I tried to do a Import-Module Send-MailKitMessage and I got a whole slew of errors:

PS C:\Windows\system32> Import-Module Send-MailKitMessage
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:85 char:88
+ ... TPServer, $Port, ($UseSecureConnectionIfAvailable.IsPresent ? [MailKi ...
+                                                                 ~
Unexpected token '?' in expression or statement.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:85 char:87
+ ... SMTPServer, $Port, ($UseSecureConnectionIfAvailable.IsPresent ? [Mail ...
+                                                                  ~
Missing closing ')' in expression.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:85 char:87
+ ... SMTPServer, $Port, ($UseSecureConnectionIfAvailable.IsPresent ? [Mail ...
+                                                                  ~
Missing ')' in method call.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:25 char:9
+     Try {
+         ~
Missing closing '}' in statement block or type definition.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:85 char:181
+ ... SocketOptions]::Auto : [MailKit.Security.SecureSocketOptions]::None))
+                                                                        ~
The Try statement is missing its Catch or Finally block.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:9 char:31
+ function Send-MailKitMessage(){
+                               ~
Missing closing '}' in statement block or type definition.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:85 char:181
+ ... SocketOptions]::Auto : [MailKit.Security.SecureSocketOptions]::None))
+                                                                        ~
Unexpected token ')' in expression or statement.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:85 char:182
+ ... SocketOptions]::Auto : [MailKit.Security.SecureSocketOptions]::None))
+                                                                         ~
Unexpected token ')' in expression or statement.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:92 char:5
+     }
+     ~
Unexpected token '}' in expression or statement.
At C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psm1:109 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Import-Module : The module to process 'Send-MailKitMessage.psm1', listed in field 'ModuleToProcess/RootModule' of
module manifest 'C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psd1' was
not processed because no valid module was found in any module directory.
At line:1 char:1
+ Import-Module Send-MailKitMessage
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Send-MailKitMessage:String) [Import-Module], PSInvalidOperationExc
   eption
    + FullyQualifiedErrorId : Modules_ModuleFileNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

It seems as if there is a syntax error or something.

astrohart commented 2 years ago

UPDATE

image

Figure 1. The files do indeed exist on the machine that is trying to call them.

Import-Module : The module to process 'Send-MailKitMessage.psm1', listed in field 'ModuleToProcess/RootModule' of
module manifest 'C:\Program Files\WindowsPowerShell\Modules\Send-MailKitMessage\3.1.0\Send-MailKitMessage.psd1' was
not processed because no valid module was found in any module directory.

Listing 1. Portion of the error message that says there are files missing, which isn't true.

Please see Listing 1. It's a portion of the error message listing that I gave you above, that says it can't find files that are, in fact, there, as shown in Figure 1.

Maybe it is a permissions issue?

Regards,

Brian Hart

austineric commented 2 years ago

Hi Brian, Backwards compatibility for Windows PowerShell has been added in 3.2.0-preview1. Give the preview module a try and let me know how things go: https://www.powershellgallery.com/packages/Send-MailKitMessage/3.2.0-preview1

Thanks, Eric