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

No add method for MimeKit.InternetAddressList #29

Closed MihaIvan closed 2 years ago

MihaIvan commented 2 years ago

I followed the example to create a send a message. Here is an excerpt from the code:

$Recipients = [MimeKit.InternetAddressList]::new $Recipients.add([MimeKit.InternetAddress]"mikelusicic@computrolllc.com")

This produces the error below:

9 | $Recipients.add([MimeKit.InternetAddress]"mikelusicic@computrolllc.co … | ~~~~~~~~~~~~~~~~~ | Method invocation failed because [System.Management.Automation.PSMethod] does | not contain a method named 'add'.

Further down I have the send coded as thus:

Send-MailKitMessage -UseSecureConnectionIfAvailable $UseSecureConnectionIfAvailable -Credential $wkCreds -SMTPServer $Server -Port $Port -From $From -RecipientList $Recipients -Subject $Subject ` -TextBody $Body

This gives this error:

Line | 24 | -RecipientList $Recipients ` | ~~~ | Cannot process argument transformation on parameter 'RecipientList'. Cannot | convert the "MimeKit.InternetAddressList | new(System.Collections.Generic.IEnumerable[MimeKit.InternetAddress] addresses), | MimeKit.InternetAddressList new()" value of type | "System.Management.Automation.PSMethod" to type "MimeKit.InternetAddressList".

By the way, where is the documentation for this? Surely there is more than just the example. Also, when trying to update the help, it says it could not update the help for this object.

austineric commented 2 years ago

Hi @MihaIvan, In your sample you need to change this: $Recipients = [MimeKit.InternetAddressList]::new

To this: $Recipients = [MimeKit.InternetAddressList]::new()

Regarding documentation - there isn't additional documentation beyond the example since that includes usage and datatypes, there isn't much else to include.

MihaIvan commented 2 years ago

I tried this, and it is not working. Sorry to be a bother. It looks like it cannot find the Mime objects.

Line | 7 | $From = @.*** … | ~~~~~~~~ | Unable to find type [MimeKit.MailboxAddress].

InvalidOperation: C:\Users\MikeL\Documents\PowerShell Scripts\Test Email.ps1:8:15 Line | 8 | $Recipients = [MimeKit.InternetAddressList]::new() | ~~~~~~~~~ | Unable to find type [MimeKit.InternetAddressList].

InvalidOperation: C:\Users\MikeL\Documents\PowerShell Scripts\Test Email.ps1:11:18 Line | 11 | @.*** … | ~~~~~~~ | Unable to find type [MimeKit.InternetAddress].

From: Eric Austin @.> Sent: Thursday, September 15, 2022 3:09 PM To: austineric/Send-MailKitMessage @.> Cc: Mike Lusicic @.>; Mention @.> Subject: Re: [austineric/Send-MailKitMessage] No add method for MimeKit.InternetAddressList (Issue #29)

Hi @MihaIvanhttps://github.com/MihaIvan, In your sample you need to change this: $Recipients = [MimeKit.InternetAddressList]::new

To this: $Recipients = [MimeKit.InternetAddressList]::new()

Regarding documentation - there isn't additional documentation beyond the example since that includes usage and datatypes, there isn't much else to include.

— Reply to this email directly, view it on GitHubhttps://github.com/austineric/Send-MailKitMessage/issues/29#issuecomment-1248560782, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACTBPNYWGZFLIUOMDLYRUHTV6N66BANCNFSM6AAAAAAQNPRJFA. You are receiving this because you were mentioned.Message ID: @.***>

austineric commented 2 years ago

That error is a result of not running this statement at the beginning of the script: using module Send-MailKitMessage

That brings the required packages like MimeKit into scope for the session.