特定の電子メールを所定のユーザーに送信し、Outlookを使用し、Outlookが同じマシン(Windowsプラットフォーム上)で実行されるのを待ちます。JenkinsはOutlookでPowerShellスクリプトを使用して電子メールを送信できません
Jenkinsでは、このPowerShellスクリプトファイルとバッチファイル(PowerShellファイルが組み込まれている)を使ってこのメールを送信してみました。
最初に私はエラーThe remote procedure call failed
に遭遇しましたが、何とかそれはなくなってしまい、電子メールを送信しません。 cmdまたはPowerShellターミナルを使用すると、完璧に動作します。 のような私のコード:
# Filters and zips the files before sending by email
Function PreProcessAttachments
{
[cmdletBinding()]
param(
[Parameter(Mandatory=$true)] [string]$integrationOutputFilePath,
[Parameter(Mandatory=$true)] [string]$updateLogFilePath)
$attachments = @()
if (Test-Path $integrationOutputFilePath)
{
$attachments += $integrationOutputFilePath
}
else
{
Write-Verbose ("Attachment file $integrationOutputFilePath " +
"does not exist. Ignoring..");
}
if (Test-Path $updateLogFilePath)
{
$attachments += $updateLogFilePath
}
else
{
Write-Verbose ("Attachment file $integrationOutputFilePath " +
"does not exist. Ignoring..");
}
return $attachments
}
Function ReportError
{
[cmdletBinding()]
param(
[Parameter(Mandatory=$true)] [string]$stream,
[Parameter(Mandatory=$true)] [string]$integrationOutputFilePath,
[Parameter(Mandatory=$true)] [string]$updateLogFilePath)
$attachments = PreProcessAttachments $integrationOutputFilePath
$updateLogFilePath;
$subject = "[Integration Internal Error] at $stream"
$body = "An internal error has occurred during integration.`n";
$body += "`nIntegration Log is attached to this e-mail.`n"
$recipients = "[email protected]"
write-output "Sending integration internal error email to: $recipients"
try
{
SendEmailUsingOutLook $subject $recipients $body $attachments | Out-Null
}
catch
{
Write-Warning "Couldn't send integration internal error emails $_"
}
}
# send e-mail using OutLook
# note: Attachments should be an array:
Function SendEmailUsingOutLook
{
[cmdletBinding()]
Param(
[Parameter(Mandatory=$true)] [string]$subject,
[Parameter(Mandatory=$true)] [string]$to,
[Parameter(Mandatory=$true)] [string]$body,
$attachments)
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = $to
$Mail.Subject = $subject
$Mail.Body = $body
if ($attachments)
{
foreach ($file in $attachments)
{
$Mail.Attachments.Add($file)
}
}
$Mail.Send()
}
Function StartPocess
{
$confFile = "path\to\myconf.xml"
LoadConfs $confFile
ReportError -stream $stream
-integrationOutputFilePath $integrationOutputFilePath
-updateLogFilePath $updateLogFilePath
}
# Start the script:
StartPocess;
実装方法は?あなたのスクリプトは何ですか?どのようにそれを実行するのですか?いくつかのコードを表示するので、私たちは何か話をします。 – restless1987
私は問題がコードではないと思った、それはジェンキンスやウィンドウのパーミッションについての何かだと思った[最小、完全で、かつ、検証可能な例](http://stackoverflow.com/help/mcve) – Clijsters
を追加してください。とにかくコードを追加したものは何でも。 – tolgayilmaz