Hi Team,<\/p>\n
i would like to seek you help.<\/p>\n
see my script if its correct , i just want to send mail if my file not exist, im using gmail<\/p>\n
Thank<\/p>\n
$Mail=import-csv 'C:\\VMWare vCenter PID Enumeration\\testemail.csv'\n$path=\"C:\\VMWare vCenter PID Enumeration\"\n$input=Test-Path -Path \"$path\\ListofvCenter.txt\"\n$userinput=test-path -Path \"$path\\user.txt\"\n$passinput=test-path -Path \"$path\\pass.txt\"\n$Email=Test-Path -Path \"$path\\email.csv\"\n\n$Files=Get-ChildItem -Path 'C:\\VMWare vCenter PID Enumeration' \n\nforeach($Filename in $Files){\n if($Filename.Name -eq \"email.csv\"){\n $FileEmail =$true\n } \n Else{\n $FileEmail= $false\n }\n\n if($Filename.Name -eq \"ListofvCenter.txt\"){\n $FilevCenter =$true\n \n } \n Else\n {\n $FilevCenter= $false\n }\n \n if($Filename.Name -eq \"pass.txt\"){\n $Filepass =$true\n \n } \n Else{\n $Filepass= $false\n }\n \n if($Filename.Name -eq \"user.txt\"){\n $Fileuser =$true \n } \n Else{\n $Fileuser= $false\n }\n\n}\n\n$mail=import-csv 'C:\\VMWare vCenter PID Enumeration\\testemail.csv'\n$e=\"\"\nForeach($useremail in $mail){\n$E+=$useremail.to + \",\" \n$trim=$E.TrimEnd(\",\") \n\n$emailSmtpServer = $useremail.SMTP #\"smtp.gmail.com\"\n$emailSmtpServerPort = \"587\"\n$emailSmtpUser = \"[email protected]\"\n$emailSmtpPass = \n\n$emailFrom = $useremail.'From '\n$emailTo = $trim.TrimEnd(\",\") \n\n$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )\n$emailMessage.Subject = \"My test mail $($Env:COMPUTERNAME)\" \n$emailMessage.Body = \"Hi Hello Test mail Only\"\n$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )\n$SMTPClient.EnableSsl = $True\n$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );\n$SMTPClient.Send( $emailMessage )\n\n}\n$emailMessage.Attachments.Dispose()\n$emailMessage.Dispose()\n\n<\/code><\/pre>","upvoteCount":2,"answerCount":4,"datePublished":"2021-04-16T09:52:39.000Z","author":{"@type":"Person","name":"marlon3","url":"https://community.spiceworks.com/u/marlon3"},"suggestedAnswer":[{"@type":"Answer","text":"Hi Team,<\/p>\n
i would like to seek you help.<\/p>\n
see my script if its correct , i just want to send mail if my file not exist, im using gmail<\/p>\n
Thank<\/p>\n
$Mail=import-csv 'C:\\VMWare vCenter PID Enumeration\\testemail.csv'\n$path=\"C:\\VMWare vCenter PID Enumeration\"\n$input=Test-Path -Path \"$path\\ListofvCenter.txt\"\n$userinput=test-path -Path \"$path\\user.txt\"\n$passinput=test-path -Path \"$path\\pass.txt\"\n$Email=Test-Path -Path \"$path\\email.csv\"\n\n$Files=Get-ChildItem -Path 'C:\\VMWare vCenter PID Enumeration' \n\nforeach($Filename in $Files){\n if($Filename.Name -eq \"email.csv\"){\n $FileEmail =$true\n } \n Else{\n $FileEmail= $false\n }\n\n if($Filename.Name -eq \"ListofvCenter.txt\"){\n $FilevCenter =$true\n \n } \n Else\n {\n $FilevCenter= $false\n }\n \n if($Filename.Name -eq \"pass.txt\"){\n $Filepass =$true\n \n } \n Else{\n $Filepass= $false\n }\n \n if($Filename.Name -eq \"user.txt\"){\n $Fileuser =$true \n } \n Else{\n $Fileuser= $false\n }\n\n}\n\n$mail=import-csv 'C:\\VMWare vCenter PID Enumeration\\testemail.csv'\n$e=\"\"\nForeach($useremail in $mail){\n$E+=$useremail.to + \",\" \n$trim=$E.TrimEnd(\",\") \n\n$emailSmtpServer = $useremail.SMTP #\"smtp.gmail.com\"\n$emailSmtpServerPort = \"587\"\n$emailSmtpUser = \"[email protected]\"\n$emailSmtpPass = \n\n$emailFrom = $useremail.'From '\n$emailTo = $trim.TrimEnd(\",\") \n\n$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )\n$emailMessage.Subject = \"My test mail $($Env:COMPUTERNAME)\" \n$emailMessage.Body = \"Hi Hello Test mail Only\"\n$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )\n$SMTPClient.EnableSsl = $True\n$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );\n$SMTPClient.Send( $emailMessage )\n\n}\n$emailMessage.Attachments.Dispose()\n$emailMessage.Dispose()\n\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2021-04-16T09:52:39.000Z","url":"https://community.spiceworks.com/t/how-can-i-send-mail-if-the-file-not-exist/797098/1","author":{"@type":"Person","name":"marlon3","url":"https://community.spiceworks.com/u/marlon3"}},{"@type":"Answer","text":"If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n