使用Powershell启动Outlook 2007,显示IMAP收件箱

时间:2015-12-03 14:49:24

标签: powershell outlook

这些天我开始进入Powershell,我正试图以干净的方式启动Outlook 2007(它应该在没有太多或任何修改的情况下在多台计算机上运行)并显示第一个帐户(imap)收件箱。 / p>

我已经在How to specify a subfolder of Inbox using Powershell找到了答案,但是这会在启动时关注本地收件箱。我们不使用本地收件箱,因为所有客户都有IMAP帐户,因此在启动时显示它会很方便。

谢谢!

编辑:

我在上述链接问题中使用的代码是:

$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox);
$inbox.Display()

如上所述,这会打开本地收件箱,但我找不到选择IMAP帐户收件箱的命令。

1 个答案:

答案 0 :(得分:1)

所以,以前我在脚本中用作$Outlook = New-Object -ComObject Outlook.Application $Namespace = $outlook.GetNameSpace("MAPI") $MyAcct = $Namespace.Folders | ?{$_.Name -match $env:USERNAME} $Inbox = $MyAcct.Folders | ?{$_.Name -match "Inbox"} 的替代方法。这将查看可用帐户,并尝试查找包含用户登录名的帐户(因此,如果我使用用户名TMTech登录到我的计算机,则会查看包含TMTech字符串的所有帐户,例如TMTech @ email.com)。然后它会查看一个名为Inbox的帐户的文件夹,然后离开那里。

<?php
$sql = "SELECT * FROM posts WHERE image_featured!='' ORDER BY id DESC LIMIT 5";
$query = mysqli_query($connection, $sql);

while($row = mysqli_fetch_array($query)){
$id = $row["id"];
$current_width = $row["width"];
$current_height = $row["height"];
if ($current_width > $current_height){
$current_layout = 'horizontal';
} // end if
if ($current_width == $current_height){
$current_layout = 'square';
} // end if
if ($current_width < $current_height){
$current_layout = 'vertical';
} // end if

echo 'Current: '.$current_layout.' (ID: '.$id.')<br/>';

$nextsql = "SELECT * FROM posts WHERE id > $id AND image_featured!='' LIMIT 1"; 
$nextquery = mysqli_query($connection, $nextsql);
if(mysqli_num_rows($nextquery) > 0) {
while($nextrow = mysqli_fetch_array($nextquery)){
$next_id  = $nextrow['id'];
$next_width = $nextrow["width"];
$next_height = $nextrow["height"];
if ($next_width > $next_height){
$next_layout = 'horizontal';
} // end if
if ($next_width == $next_height){
$next_layout = 'square';
} // end if
if ($next_width < $next_height){
$next_layout = 'vertical';
} // end if
echo 'Next: '.$next_layout.' (ID: '.$next_id.')<br/>';
} // end while
} // end if

$previoussql= "SELECT * FROM posts WHERE id < $id AND image_featured!='' LIMIT 1"; 
$previousquery = mysqli_query($connection, $previoussql);
if(mysqli_num_rows($previousquery) > 0) {
while($previousrow = mysqli_fetch_array($previousquery)){
$previous_id  = $previousrow['id'];
$previous_width = $previousrow["width"];
$previous_height = $previousrow["height"];
if ($previous_width > $previous_height){
$previous_layout = 'horizontal';
} // end if
if ($previous_width == $previous_height){
$previous_layout = 'square';
} // end if
if ($previous_width < $previous_height){
$previous_layout = 'vertical';
} // end if
echo 'Previous: '.$previous_layout.' (ID: '.$previous_id.')<br/>';
} // end while
} // end if

echo '<hr/>';

} // end while 1
?>

现在这仍然引用了MAPI命名空间,但我认为interop库包含了MAPI命名空间中的所有内容,所以我认为它仍然可以工作。