我正在尝试使用MailKit dll作为Powershell中的程序集,但它无法正常工作。 我尝试使用add-type和[System.Reflection.Assembly]方法,但没有成功。 mailkit库的链接:
https://github.com/jstedfast/MailKit
使用这种方法:
$path="$HOME\.nuget\packages\mailkit\1.16.1\lib\net451\MailKit.dll"
[System.Reflection.Assembly]::LoadFile($path)
其他内容中没有引用程序集。 用这种方法:
Add-Type -Path $path
这是错误:
- Add-Type -Path $ path
- ~~~~~~~~~~~~~~~~~~~~
- CategoryInfo:NotSpecified:(:) [Add-Type],ReflectionTypeLoadException
- FullyQualifiedErrorId:System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
由于
丹尼尔
答案 0 :(得分:1)
检查路径。对我来说, private void OnMyListViewContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
var containerVisual = ElementCompositionPreview.GetElementVisual(args.ItemContainer);
if (args.InRecycleQueue)
{
containerVisual.ImplicitAnimations = null;
}
else
{
// EnableImplicitAnimation() is available at
// https://github.com/JustinXinLiu/Continuity/blob/0015a96897c138e09d8604267df46da936b66838/Continuity/Extensions/CompositionExtensions.Implicit.cs#L144
containerVisual.EnableImplicitAnimation(VisualPropertyType.Offset, 400.0f);
}
}
:
$MailKitDllPath
答案 1 :(得分:0)
我发现MailKit有对MimeKit dll的引用,但加载MailKit.dll没有错误,因此也需要加载MimeKit.dll。
[System.Reflection.Assembly]::LoadFile("$home\.nuget\packages\MailKit\1.16.1\lib\net451\MailKit.dll")
[System.Reflection.Assembly]::LoadFile("$home\.nuget\packages\mimekit\1.16.1\lib\net451\MimeKit.dll")
答案 2 :(得分:0)
此完整脚本可能会帮助其他人:
# search for "Test" in subject and MoveTo Archive/2018
$packages = split-path -parent $MyInvocation.MyCommand.Definition
add-type -path (Join-Path $packages "MimeKit.dll") | Out-Null
add-type -path (Join-Path $packages "MailKit.dll") | Out-Null
#Server and Mailbox Definitions
$mailserver = "mail.corp.com"
$username = "email@corp.com"
$password = "password"
$cnn = New-Object MailKit.Net.Imap.ImapClient
$cnn.Connect($mailserver)
$cnn.Authenticate($username,$password)
$cnn.Inbox.Open([MailKit.FolderAccess]::ReadWrite)
$query = [MailKit.Search.SearchQuery]::SubjectContains("Test")
#$orderBy = @([MailKit.Search.OrderBy]::Arrival)
#filter
$uids = $cnn.Inbox.Search($query) #$orderby) not working yet
#download
$msgs = $cnn.Inbox.Fetch($uids, [MailKit.MessageSummaryItems]::UniqueId -bor [Mailkit.MessageSummaryItems]::BodyStructure)
#do something
#move
$archive = $cnn.GetFolder("Archive.2018")
$cnn.Inbox.MoveTo($uids, $archive)
$cnn.Disconnect($true)