Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Function Createfile
  2. {
  3. $location = "C:\Mailbot\New\"
  4. $mailgroup = "jrosolen@balmain.com.au"
  5. $date = (Get-Date).ToString('MM-dd-yyyy')
  6. $outfile = $location+$date+"test_report.txt"
  7. $subject = "Test email, date: " + $date
  8. $mailto = ""
  9. foreach($mail in $mailgroup){$mailto = $mailto + $mail + ";"}
  10. $mailto = $mailto.trimend(";")
  11. $body = "How long can I sit`r`nNursing my coffee until`r`nI have to do work?`r`n`r`nTest Username: T_Test`r`nTest Password: Password"
  12. $output = $mailto + "`r`n" + $subject + "`r`n" + $body
  13. $output | out-file $outfile
  14. }
  15.  
  16. Function SendFile
  17. {
  18. $filelist = Get-ChildItem -path c:\mailbot\New\ -filter "*.txt" | ForEach-Object {
  19.  
  20. $filed = $_.fullname
  21.  
  22. $ToField = get-content -path $filed | select-object -first 1
  23. $Recipients = $ToField -split ";"
  24. $SubjectField = get-content -path $filed | select-object -Skip 1 | Select-Object -First 1
  25. $BodyField = get-content -path $filed | select-object -Skip 2 | Out-String
  26.  
  27. $Recipients | foreach {
  28. Write-host "TO: " $_
  29. }
  30. Write-host "SUBJECT: " $SubjectField
  31. Write-host "BODY: " $BodyField
  32.  
  33. Send-MailMessage -to $Recipients -from "mailbot@balmain.com.au" -subject $SubjectField -Body $BodyField -SmtpServer "192.168.6.51"
  34.  
  35. move-item $filed C:\Mailbot\Archive\
  36. }
  37. }
  38.  
  39. Sendfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement