首页 > 解决方案 > 如何找到 Outlook 的路径,以便我可以发送带有脚本的电子邮件

问题描述

我创建了一个 powershell 脚本来使用任务计划程序自动发送 csv 文件。我觉得我的路径好像犯了一个愚蠢的错误,因为什么都没有发送。

我已经测试了下面的脚本。

if($args.Count -lt 1)
{
Write-Host "Use: SendMail.ps1 <"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Outlook 2010.lnk">"
Write-Host
Write-Host  "<"C:\CSV">"
Write-Host
exit
}

$FullPath=$args[0]

#Get an Outlook application object

$o = New-Object -com Outlook.Application

$mail = $o.CreateItem(0)

#2 = High importance message
$mail.importance = 2

$mail.subject = "CSV File"
$mail.body = "Here is the CSV file."

#separate multiple recipients with a ";"
$mail.To = <---->
#$mail.CC = <OTHER RECIPIENT 1>;<OTHER RECIPIENT 2>

# Iterate over all files and only add the ones that have an .csv extension
$files = Get-ChildItem $FullPath

for ($i=0; $i -lt $files.Count; $i++) {

$outfileName = $files[$i].FullName
$outfileNameExtension = $files[$i].Extension

# if the extension is the one we want, add to attachments
if($outfileNameExtension -eq ".csv")
{
$mail.Attachments.Add($outfileName);
}
}

$mail.Send()

# give time to send the email
Start-Sleep 20

# quit Outlook
$o.Quit()

#end the script
exit

我认为以下是不正确的:

Write-Host "Use: SendMail.ps1 <"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Outlook 2010.lnk">"

但我不确定路径应该是什么。

标签: powershelloutlook

解决方案


路径应该是这样的:

C:\Program Files (x86)\Microsoft Office\root\Office16\Outlook.exe

此链接有一些方法可以找到正在运行的进程的可执行文件的路径:

http://www.softwareok.com/?seite=faq-Windows-10&faq=152


推荐阅读