我需要使用 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 = "[email protected]"
$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”的新檔案夾中。我如何實作這一目標?
uj5u.com熱心網友回復:
我終于知道為什么它不起作用了。查看模塊的后端代碼 ( https://www.powershellgallery.com/packages/Mailozaurr/0.0.16/Content/Mailozaurr.psm1 ),收件箱以只讀模式打開。因此,解決方案是關閉收件箱并以讀寫模式打開它,或者在 Get-ImapFolder 命令上設定 FolderAccess。因此
$FromAddress = "[email protected]"
$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 命令中的零代表要移動的第一封電子郵件。感謝@PrzemyslawKlys 在https://github.com/EvotecIT/Mailozaurr/issues/22提供幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/384904.html
標籤:电源外壳
