gpt4 book ai didi

email - 我可以使用PowerShell将电子邮件附件从Office 365保存到文件共享吗?

转载 作者:行者123 更新时间:2023-12-02 23:58:23 25 4
gpt4 key购买 nike

我已经看到了几种使用PowerShell来自动化本地Outlook客户端的解决方案,但是我希望它可以在服务器端运行:使用给定的帐户访问服务器,检查未读邮件,将所有附件保存到文件共享中并标记为消息已读。

最佳答案

这需要安装Exchange Managed Services API

$ewsPath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
Add-Type -Path $ewsPath

$ews = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
$cred = (Get-Credential).GetNetworkCredential()
$ews.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $cred.UserName, $cred.Password, $cred.Domain
$ews.AutodiscoverUrl( "user@domain.com", {$true} )
$results = $ews.FindItems(
"Inbox",
( New-Object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 100 )
)
$MailItems = $results.Items | where hasattachments

foreach ($MailItem in $MailItems){

$MailItem.Load()

foreach($Attachment in $MailItem.Attachments){
$Attachment.Load()
$File = new-object System.IO.FileStream(("C:\Temp\” + $attachment.Name.ToString()), [System.IO.FileMode]::Create)
$File.Write($attachment.Content, 0, $attachment.Content.Length)
$File.Close()
}
}

关于email - 我可以使用PowerShell将电子邮件附件从Office 365保存到文件共享吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37038133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com