将不同的电子邮件设置为带Powershell的默认电子邮件
我正在创建一个脚本,该脚本将在用户电子邮件帐户中查找电子邮件,然后从电子邮件中下载附件 这会在写入时自动选择用户的默认电子邮件帐户。但是,我想在Outlook中使用第二个电子邮件帐户 有没有办法更改它搜索的电子邮件帐户将不同的电子邮件设置为带Powershell的默认电子邮件,powershell,outlook,Powershell,Outlook,我正在创建一个脚本,该脚本将在用户电子邮件帐户中查找电子邮件,然后从电子邮件中下载附件 这会在写入时自动选择用户的默认电子邮件帐户。但是,我想在Outlook中使用第二个电子邮件帐户 有没有办法更改它搜索的电子邮件帐户 $outlook = New-Object -comobject outlook.application $namespace = $outlook.GetNamespace("MAPI") #Below: 6 is the default for inbox, so this
$outlook = New-Object -comobject outlook.application
$namespace = $outlook.GetNamespace("MAPI")
#Below: 6 is the default for inbox, so this saves the user from having to select the inbox folder. Change if emails w/ attatchements are going to a different folder.
$folder = $namespace.GetDefaultFolder(6)
$filepath = "C:\Users\Documents\PowerShell"
$folder.Items | foreach {
$_.attachments | foreach {
$filename = $_.filename
If ($filename.Contains("example1.xls")) {
$_.saveasfile((Join-Path $filepath $filename))
Rename-Item -LiteralPath '.\example1.xls' -NewName "Server.xls"
}
If ($filename.Contains("example2.xls")) {
$_.saveasfile((Join-Path $filepath $filename))
Rename-Item -LiteralPath '.\example2.xls' -NewName "Workstation.xls"
}
}
}
不要使用
$namespace.GetDefaultFolder(6)
,而是从名称空间.Stores
集合中找到适当的存储对象,然后调用存储.GetDefaultFolder
如果另一个邮箱不在
名称空间.Stores
集合中,请调用名称空间.CreateRecipient
/名称空间.GetSharedDefaultFolder
。听起来您试图做的是更改正在扫描的文件夹?如果是这样,您需要更改$folder=$namespace.GetDefaultFolder(6)
,如果手动干预合适,您还可以执行$folder=$namespace.PickFolder()
打开Outlook的“选择文件夹”gui,该gui将所选文件夹分配给$folder变量。