我有一个处理CUBES的脚本,并且如果在参数中未输入任何多维数据集名称,则生成的日志文件将不会获得CUBE名称,因为其空白(该文件也不包含任何内容),因此一切正常,除了我注意到当我收到处理日志的电子邮件时,这些奇怪的名字和数字会添加到附件中。(ATT96614等)
这是生成的日志:
这是一封带有日志的电子邮件...但是以某种方式附加了随机名称和数字
这是我正在使用的发送电子邮件功能:
Function Send-Email {
Param (
[Parameter(`
Mandatory=$true)]
[String]$SendTo,
[Parameter(`
Mandatory=$true)]
[String]$Subject,
[Parameter(`
Mandatory=$false)]
[String]$Body,
[Parameter(`
Mandatory=$true)]
[String]$EmailFrom,
[Parameter(`
mandatory=$false)]
[String]$attachment,
[Parameter(`
mandatory=$true)]
[String]$Username,
[Parameter(`
mandatory=$true)]
[String]$Password
)
$SMTPServer = $SmtpServer
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$SendTo,$Subject,$Body)
if ($attachment -ne $null) {
$SMTPattachment = New-Object System.Net.Mail.Attachment($attachment)
$SMTPMessage.Attachments.Add($SMTPattachment)
}
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, $SmtpPort)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$SMTPClient.Send($SMTPMessage)
Remove-Variable -Name SMTPClient
Remove-Variable -Name Username
Remove-Variable -Name Password
}
这是名为:
的发送电子邮件Send-EMail -EmailFrom $From_Email -SendTo $To_Email -Body "Processing job failed!`r`n`r`nPerhaps the CUBE or Process Server is invalid?" -Subject $Job_Failed_Email_Subject -attachment $process_output -Username $SmtpUser -Password $SmtpPassword
有什么主意吗?
答案 0 :(得分:2)
When files are attached to emails the file names are written into the mime headers. At a guess, the method you're using to attach the file (supplying the file name to the relevant Attachment constructor) is dropping the name and generating its own
Try setting the name on the attachment directly yourself (after you create it, before you add it):
$SMTPattachment.ContentDisposition.FileName = "log.txt";