Powershell:将电子邮件移动到Gmail中的其他文件夹



我需要使用Powershell并将GMAIL收件箱中的电子邮件移动到其他文件夹。我正在使用Powershell模块Mailozaurr通过IMAP连接到Gmail(https://evotec.xyz/mailozaurr-new-mail-toolkit-smtp-imap-pop3-with-support-for-oauth-2-0-and-graphapi-for-powershell/)。我能够正确登录并阅读收件箱中的电子邮件。这是我的代码:

$FromAddress = "A12345@gmail.com"
$Password = "MY_password"
$Client = Connect-IMAP -Server 'imap.gmail.com' -Password $Password -UserName $FromAddress -Port 993 -Options Auto
Get-IMAPFolder -Client $Client -Verbose
foreach ($Email in $client.Data.Inbox)
{
if ($Email.from -notlike "test") {continue}
$Email
Break
}

在这个阶段,我想将$email移动到一个名为"的新文件夹中;NewFolder";。我该如何做到这一点?

我终于明白了为什么它不起作用。查看模块的后端代码(https://www.powershellgallery.com/packages/Mailozaurr/0.0.16/Content/Mailozaurr.psm1),收件箱以只读模式打开。因此,解决方案是关闭收件箱并以读写模式打开它,或者在Get-ImapFolder命令上设置FolderAccess。因此

$FromAddress = "A12345@gmail.com"
$Password = "MY_password"
$Client = Connect-IMAP -Server 'imap.gmail.com' -Password $Password -UserName $FromAddress -Port 993 -Options Auto
Get-IMAPFolder -Client $Client -FolderAccess ReadWrite -Verbose
foreach ($Email in $client.Data.Inbox)
{
$Email
$TestFolder = $Client.data.GetFolder("Test")
$client.Data.Inbox.MoveTo(0, $TestFolder)
Break
}

Moveto命令中的ZERO表示要移动的第一封电子邮件。感谢@PrzemyslawKlys在https://github.com/EvotecIT/Mailozaurr/issues/22

最新更新