我希望通过Powershell发送带有提醒的电子邮件Outlook任务,这可能吗?任务类似于下图:
powershell内置功能是否可以创建此任务,而不是使用“新对象Net.Mail.MailMessage”创建普通电子邮件?有任何示例代码/文档可供参考吗?
答案 0 :(得分:0)
谷歌快速搜索显示了这些
答案 1 :(得分:0)
不,那不是这样做的。如本文所述,这是一个.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