VMware Cloud Community
rachappachalmi
Enthusiast
Enthusiast

Adding multiple attachement which dont have any extensions

Hi All,

I am using below script to send mails with multiple attachments but it sending only first file in the folder, need your help.

$runDateTime = Get-Date   
$smtp = "smtp.server.com"   
$to = "mymailid@com"    
$cc = "mymailid@com"    
$from = "mymailid@com"       
$subject = "HangIssueReport_CL04 - $runDateTime"
$attachmentLocation = "E:\Report\ovc1.2.3.4"
$attachmentLocation = "E:\Report\ovc2.3.4.5"
$attachmentLocation = "E:\Report\ovc3.4.5..6"
$attachmentLocation = "E:\Report\ovc4.5.6.7"

$body = "Hi Team, Good Day, <br><br>"        
$body += "This is the <b>lsof report </b> you received at <i>$runDateTime.</i><br><br>"   
$body += "Have a great day!<br><br>"   
$body += "Thank you <br><br>"
$body += "Test<br>"
$body += "Test "      
Send-MailMessage -SmtpServer $smtp -To $to -Cc $cc -From $from -Subject $subject -Body $body -BodyAsHtml -Attachments $attachmentLocation 
 
Write-Host "====== Email sent! ======"

$attachments = @()
foreach($file in $files){
    $filename = [system.io.path]::GetFileName($file.FullName)
    $attachments += $file.fullname
    $body += "TEST <br /><img src='" + $filename + "'/>TEST <br />"

0 Kudos
1 Reply
LucD
Leadership
Leadership

Are you sure this is sending anything at all?

What is in $files?

This looks as if you copy/pasted parts of 2 different scripts together


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos