Send-MailKitMessage icon indicating copy to clipboard operation
Send-MailKitMessage copied to clipboard

No add method for MimeKit.InternetAddressList

Open MihaIvan opened this issue 3 years ago • 3 comments

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]"[email protected]")

This produces the error below:

9 | $Recipients.add([MimeKit.InternetAddress]"[email protected] … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 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.

MihaIvan avatar Sep 15 '22 15:09 MihaIvan

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.

austineric avatar Sep 15 '22 20:09 austineric

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: @.***>

MihaIvan avatar Sep 15 '22 21:09 MihaIvan

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.

austineric avatar Sep 16 '22 00:09 austineric