EvotecIT / Mailozaurr

Mailozaurr is a PowerShell module that aims to provide SMTP, POP3, IMAP and probably some other ways to interact with Email. Underneath it uses MimeKit and MailKit libraries written by Jeffrey Stedfast.
MIT License
149 stars 15 forks source link

-SkipCertificateValidatation does not seem to work #53

Open tonyguadagno opened 6 months ago

tonyguadagno commented 6 months ago

hi, i am executing this command:

Send-EmailMessage -to "tguadagno@company.com" -From "lnb-backup@company.com" -Subject "test" -Text "test" -Server "mail.company.com" -port 25 -SkipCertificateValidatation

the cert on port 25 does NOT match "mail.company.com" but i am using the -SkipCertificateValidatation switch....this is what i get:

WARNING: Send-EmailMessage - Error: Exception calling "Connect" with "3" argument(s): "An error occurred while attempting to establish an SSL or TLS connection.

The host name did not match the name given in the server's SSL certificate.
"
WARNING: Send-EmailMessage - Possible issue: Port? (25 was used), Using SSL? (Auto was used). You can also try SkipCertificateValidation or SkipCertificateRevocation. 

Status        : False
Error         : Exception calling "Connect" with "3" argument(s): "An error occurred while attempting to establish an SSL or TLS connection.

                The host name did not match the name given in the server's SSL certificate.
                "
SentTo        : tguadagno@company.com
SentFrom      : lnb-backup@company.com
Message       : 
TimeToExecute : 00:00:00.0235829
Server        : mail.company.com
Port          : 25

so, why is this happening? Am I doing something wrong? thanks

PrzemyslawKlys commented 5 months ago

It was also reported in:

Seems this PR:

Broke it. @jborean93 do you think I should revert back?

jborean93 commented 5 months ago

I'm unsure why it wouldn't work, it looks like v3.2.0 is the version of MailKit that is used and the code that calls this callback is

https://github.com/jstedfast/MailKit/blob/77eb92573cec5b38bafb3a1ebdd819693ac4162f/MailKit/Net/Smtp/SmtpClient.cs#L528-L551

It's the same place that also checks the [Net.ServicePointManager]::ServerCertificateValidationCallback so both should work. Maybe pwsh class inheritance is causing problems with the type where property isn't set but that's a stretch. I don't have a mail server to test it out currently sorry so up to you if you wish to revert or investigate why the property doesn't work.