2016-09-13 2 views
0

私はこのコードを持っている:Powershell関数にファイルを添付してMS Outlook経由で送信するにはどうすればいいですか?

Function Mailer ($MSubject, $MBody, $File){ 
$Outlook = New-Object -ComObject Outlook.Application 
$Mail = $Outlook.CreateItem(0) 
$Mail.To = "[email protected]" 
$Mail.Subject = $MSubject 
$Mail.Body = $MBody 
$Mail.Attachments.Add($File) 
$Mail.Send() 
} 

私は$ファイルの変数に割り当てることによって、機能の正確なパスを提供する場合、私は動作します。しかし、私はこれを、さまざまな科目、身体、道筋に共通化したいと考えています。ファイルパスをグローバルに設定する必要がありますか?あなたの考えは? ピョートル

答えて

0

これは私が電子メールを送信するために使用するコードです:)事前に

おかげで、

$from="[email protected]" 
$to="[email protected]" 
[email protected]("[email protected]", "[email protected]") 
$subject="Weekly reports" 
$attach="c:\SchTsk\Reports\Server_Inventory_$((Get-Date).ToString('MM-dd-yyyy')).csv","C:\SchTsk\Reports\VMPlatform_$((Get-Date).ToString('MM-dd-yyyy')).csv" 
$body="This email contains weekly reports ran on the domain.<br>In an effort to reduce inbox spam, reports that generate separate files are now being attached to one weekly email." 
Send-MailMessage -from $from -To $to -cc $cc -subject $subject -SmtpServer snmp.relay.contoso.com -Body $body -BodyAsHtml -Attachments $attach 
+0

ええ、私はこれを知っています。しかし、私はこれを関数に入れたいと思っています。 – ppiotrek

0

は、実際に機能が正常に動作します。問題は、私が呼び出していたファイルパスの変数にありました。

関連する問題