PowerShell调用Outlook发送邮件


# Author: Wang Lang
$psobj=New-Object psobject
$xl=New-Object -ComObject excel.application
$xl.Visible=$false
$wb=$xl.Workbooks.Open(“C:\Users\Administrator\Desktop\info.xlsx”) #存放信息的excel文件目录
$ws=$wb.Sheets.item(1)
$all=$ws.range(“a65536”).end(-4162).row
for($i=2;$i -le 2;$i++){

$Seg_EN=$ws.Range(“A$i”).text
$Seg_CN=$ws.Range(“B$i”).text
$Email=($ws.Range(“C$i”).text).split(“;”)
$SRC_Month_EN=$ws.Range(“D$i”).text
$SRC_Month_CN=$ws.Range(“E$i”).text
$Path=$ws.Range(“F$i”).text
$Year=$ws.Range(“G$i”).text
$Month_EN=$ws.Range(“H$i”).text
$Month_CN=$ws.Range(“I$i”).text
$Day=$ws.Range(“J$i”).text
$Week_EN=$ws.Range(“K$i”).text
$Week_CN=$ws.Range(“L$i”).text
$Start=[string]$ws.Range(“M$i”).text
$End=[string]$ws.Range(“N$i”).text

$message=$SRC_Month_CN+”月份管理费用分析会安排如下:”

$sub=”管理分析报告会-Overhead Report Analysis review–$Seg_EN.”
$body=”

各位领导,

Dear All,

$message

$Year $SRC_Month_EN’s Overhead Report Analysis review is scheduled as below:

$Seg_CN $Year 年 $Month_CN 月 $Day 日($Week_CN)$Start-$End 项目楼三楼会议室

$Seg_EN Dept. $Day Oct,$Year ($Week_EN) $Start-$End,Project Building-3rd floor conference room

详细资料在附件中,请查收

Kindly find the attached files for reference.

请各位抽空参加

We appreciate your attendance.

Best regards!

Chloe Cheng

Add-Type -assembly “Microsoft.Office.Interop.Outlook”
$Outlook = New-Object -comobject Outlook.Application
$mail = $Outlook.CreateItem(1) # 1 means Meeting
$mail.MeetingStatus=[Microsoft.Office.Interop.Outlook.olMeetingStatus]::olMeeting
$mail.Start=Get-Date -Date “$Year /$Month_CN / $Day $Start”
$mail.End=Get-Date -Date “$Year /$Month_CN / $Day $End”
$mail.AllDayEvent=$false
$mail.Subject=$sub
$mail.Body=$body
$mail.Location=”3F Meeting Room”
$mail.Importance=2
$mail.ResponseRequested=$true
$mail.ReminderSet=$true
$mail.ReminderMinutesBeforeStart=5
$mail.SendUsingAccount=$Outlook.Session.Accounts[1] #发送使用的账户。
$files=Get-ChildItem -Path $Path
foreach($file in $files){
$mail.Attachments.Add($file.FullName)

}
foreach($user in $Email){
$mail.Recipients.Add($user)
}

$mail.Recipients.ResolveAll()
$mail.Send()

}
$wb.close()
$xl.Quit()

本文链接: http://www.pstips.net/send-mail-via-outlook.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

电子邮件地址不会被公开。 必填项已用*标注