0
votes

Ok, I think I have removed all identifiable info...

I have 56 files that need to go to 56 different people. I'm using PS code that I actually got from this site (that question is closed) and for the most part is working great, but I'm getting 4 error messages when running the code everytime, but they seem to be affecting the output differently everytime I run it...

See the first time I ran it, there were 4 files that didn't get sent, which makes sense (4 error messages), but when I run it again, I get the same 4 error messages, but this time only 3 emails didn't go through. To top it off, the three emails that didn't go through this time, did run successfully the first time (which also means that the 4 that didn't go through the first time, did go through the second time). So not sure how to perform route cause analysis on this :(. Anyone have any advise?

PS Code:

$csv = Import-Csv -Delimiter ";" -Path "networkfolder\Dashboard_email.csv" -header "Id","Email"
foreach ($item in $csv) {
$filename = "$($item.id)"
send-mailmessage -to $item.email -attachments $filename -body "Testing <br> Testing" -subject "Testing, may delete after confirming receipt of total count.  I will IM when script has completed." -from [email protected] -SmtpServer mailrelay.serverlocation.com -cc [email protected]
}

PS Error Messages:

1

send-mailmessage : The specified string is not in the form required for an e-mail address. At networkfolder\Email testing.ps1:5 char:5 + send-mailmessage -to $item.email -attachments $filename -body "We ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (:) [Send-MailMessage], FormatException + FullyQualifiedErrorId : FormatException,Microsoft.PowerShell.Commands.SendMailMessage 2

send-mailmessage : Could not find file 'U:\Id'. At networkfolder\Email testing.ps1:5 char:5 + send-mailmessage -to $item.email -attachments $filename -body "We ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Send-MailMessage], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage 3

send-mailmessage : Service not available, closing transmission channel. The server response was: 4.4.1 Connection timed out At Networkfolder\Email testing.ps1:5 char:5 + send-mailmessage -to $item.email -attachments $filename -body "We ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage 4

send-mailmessage : Service not available, closing transmission channel. The server response was: 4.4.1 Connection timed out At Networkfolder\Email testing.ps1:5 char:5 + send-mailmessage -to $item.email -attachments $filename -body "We ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

Also if possible, can anyone tell me how to separate paragraphs? I read that using "
" would do that, but not working for me.

1
why would you repost that?4c74356b41
I just ran it again and got the same 4 error messages, but this time, only 2 files didn't go through... 1st run 4 got dropped, 2nd run 3 got dropped, 3 run 2 got dropped....Do I have to run it two more times for all to go through? LOL...Steven Rivera
@4c73456b41, I was told to repost after taking out identifiable information.Steven Rivera
Took a long time for it to finish, but checking this morning, the good news is that it did send all of the emails! The bad news is that most of them were sent 10 times. Any work around for this?Steven Rivera
Output of Import-Csv Import-Csv -Delimiter ";" -Path "P:\Sales Finance\Steven\Dashboard_email.csv" -header "Id","Email" will help us here at least with some dummy valuesPrasoon Karunan V

1 Answers

0
votes

Try adding a Start-Sleep cmdlet in your loop.

$csv = Import-Csv -Delimiter ";" -Path "networkfolder\Dashboard_email.csv" -header "Id","Email"
foreach ($item in $csv) {
    $filename = "$($item.id)"
    send-mailmessage -to $item.email -attachments $filename -body "Testing <br> Testing" -subject "Testing, may delete after confirming receipt of total count.  I will IM when script has completed." -from [email protected] -SmtpServer mailrelay.servername.com -cc [email protected]
    Start-Sleep -m 1000
}