Emailmessage -附加一个文件类型的每个文件



我试图通过电子邮件发送某个文件类型的每个文件作为附件。如果我有
一个单一的PDF脚本工作。然而,很多都是在一天之内创造出来的。当任务调度程序运行时,我的脚本不会发送文件夹中的每个pdf。它只接收和发送一个文件。这是脚本的一部分。我也试过"foreach ($ createdproject in $sourcedir)

$sourcedir = 'E:projectFolder'   
$createdproj = Get-Item -path 'E:ProjectFolder*.pdf' 
if ($createdproj ) {
$emailSmtpServer = "smtp.domain.com"
$emailSmtpServerPort = "25"
$emailSmtpUser = "user@domain.com"
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = "admin@domain.com"
$emailMessage.To.Add( "support@IT-Help.com" )
$emailMessage.Subject = "Project Successfully Created"
$emailMessage.Attachments.Add($createdproj)
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = @"
<p>Here is a message states the csv was converted to pdf</p>
"@
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer ,        $emailSmtpServerPort )
$SMTPClient.Send( $emailMessage )

}

我也试过"foreach ($createdproj in $sourcedir)

遍历$sourcedir并不能得到目录中的所有项。你应该知道这一点,因为下一行你会得到目录中的文件。

如果你的代码是这样的,你应该能够
foreach ($proj in $createdproj) {
  $emailMessage.Attachments.Add($proj)
}

谢谢。这工作。这是最后一个:

foreach ($proj in $createdproj) {
$emailSmtpServer = "smtp.client.com"
$emailSmtpServerPort = "25"
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = "system@client.com"
$emailMessage.To.Add( "support@ITcompany.com" )
$emailMessage.Subject = "Project Successfully Created"
$emailMessage.Attachments.Add($sourcedir + $proj.name)
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = @"
<p>A CSV has been created and processed with information containing project    . </p>
"@
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer ,     $emailSmtpServerPort )
$SMTPClient.Send( $emailMessage )
}

相关内容

  • 没有找到相关文章

最新更新