【发布时间】:2020-06-04 19:12:01
【问题描述】:
我希望通过powershell发送一个带有提醒的电子邮件outlook任务,可以吗?任务类似于下图:
powershell 内置函数是否能够创建此任务,而不是使用“new-object Net.Mail.MailMessage”创建普通电子邮件?任何示例代码/文档可供参考?
【问题讨论】:
标签: powershell email outlook
我希望通过powershell发送一个带有提醒的电子邮件outlook任务,可以吗?任务类似于下图:
powershell 内置函数是否能够创建此任务,而不是使用“new-object Net.Mail.MailMessage”创建普通电子邮件?任何示例代码/文档可供参考?
【问题讨论】:
标签: powershell email outlook
快速谷歌搜索带来了这些
【讨论】:
不,那不是它的作用。这是此处记录的 .Net 类。
要将 PowerShell 与 Outlook 结合使用,您必须使用 Outlook 对象模型 (DCOM)。网络上有很多将 PowerShell 与 Outlook 结合使用的示例。进行搜索将为您找到这些内容。
这只是处理 Outlook 任务的一个示例,并为您提供了一些其他参考。
Managing an Outlook Mailbox with PowerShell
Getting Things Done – Outlook Task Automation with PowerShell
## Add-OutlookTask.ps1
## Add a task to the Outlook Tasks list
param( $description = $(throw "Please specify a description"), $category, [switch] $force )
## Create our Outlook and housekeeping variables.
## Note: If you don't have the Outlook wrappers, you'll need
## the commented-out constants instead
$olTaskItem = "olTaskItem"
$olFolderTasks = "olFolderTasks"
#$olTaskItem = 3
#$olFolderTasks = 13
$outlook = New-Object -Com Outlook.Application
$task = $outlook.Application.CreateItem($olTaskItem)
$hasError = $false
## Assign the subject
$task.Subject = $description
## If they specify a category, then assign it as well.
if($category)
{
if(-not $force)
{
## Check that it matches one of their already-existing categories, but only
## if they haven't specified the -Force parameter.
$mapi = $outlook.GetNamespace("MAPI")
$items = $mapi.GetDefaultFolder($olFolderTasks).Items
$uniqueCategories = $items | Sort -Unique Categories | % { $_.Categories }
if($uniqueCategories -notcontains $category)
{
$OFS = ", "
$errorMessage = "Category $category does not exist. Valid categories are: $uniqueCategories. " +
"Specify the -Force parameter to override this message in the future."
Write-Error $errorMessage
$hasError = $true
}
}
$task.Categories = $category
}
## Save the item if this didn't cause an error, and clean up.
if(-not $hasError) { $task.Save() }
$outlook = $null
另见此模块:
Powershell and Outlook: Create a New Outlook Task using Powershell OutlookTools Module https://github.com/AmanDhally/OutlookTools
【讨论】: