Advertisement
ekostadinov

Mail User Agent

Aug 18th, 2014
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.30 KB | None | 0 0
  1. $hour = Get-Date -Format HH
  2. $minute = Get-Date -Format mm
  3. #no need to check mail before 8a.m. and after 6 p.m. office hours
  4. #execute on every 30 mins
  5. if( (($hour -ge 8) -or ($hour -le 18)) -and (( ($minute -eq 00) -or ($minute -eq 01) ) -or ($minute -eq 30)) )
  6. {
  7.     $ie = New-Object -ComObject InternetExplorer.Application
  8.     $ie.Visible = $true
  9.     $url = "https://myMailUrl.com/?Login"
  10.     $ie.Navigate($url)
  11.     Start-Sleep -Seconds 10
  12.     $doc = $ie.Document
  13.     $counter = 0
  14.     #logic to retry 5 times
  15.     while($doc -eq $null)
  16.     {
  17.         $ie.quit()
  18.         $counter = $counter + 1
  19.         ipconfig /flushdns
  20.         Start-Sleep -Seconds 2
  21.         netsh interface set interface “Local Area Connection DISABLE
  22.         Start-Sleep 3
  23.         netsh interface set interface “Local Area Connection ENABLE
  24.         $ie = $null
  25.         $ie = New-Object -ComObject InternetExplorer.Application
  26.         $ie.Navigate($url)
  27.         $doc = $ie.Document
  28.         if($counter -eq 5)
  29.         {
  30.             [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  31.             [System.Windows.Forms.MessageBox]::Show("Error! Maybe Connection problems.")       
  32.             break
  33.         }
  34.         Start-Sleep -Seconds 2 
  35.     }
  36.     $usernameInput = $doc.getElementsByName("Username")
  37.     foreach($u in $usernameInput) {$u.value = "user.user@db.com"}
  38.     $passInput = $doc.getElementsByName("Password")
  39.     foreach($p in $passInput) {$p.value = "myPass"}
  40.     $loginBtn = $doc.getElementsByTagName("input")
  41.     foreach($i in $loginBtn) { if($i.Type -eq "submit") {$i.click()}  }
  42.     Start-Sleep -Seconds 2
  43.     $doc = $null
  44.     Start-Sleep -Seconds 25
  45.     $doc = $ie.Document
  46.     $spans = $doc.getElementsByTagName("span")
  47.     foreach($s in $spans) { if($s.InnerText -eq "Mail") {$s.click()}  }
  48.     Start-Sleep -Seconds 2
  49.     $doc = $null
  50.     $doc = $ie.Document
  51.     $refresh = $doc.getElementsByTagName("img")
  52.     #refresh IN-mailbox
  53.     foreach($i in $refresh) { if($i.Title -match "Click to refresh the current view") {$i.click()}  }
  54.     Start-Sleep -Seconds 3
  55.     $newMail = $false
  56.     foreach($i in $refresh)
  57.     {
  58.         #active only if new inbox mails
  59.         if($i.Title -match "Unread message ")
  60.         {
  61.             $ie.Visible = $true
  62.             $newMail = $true
  63.         }
  64.     }
  65.     if($newMail -ne $true)
  66.     {    
  67.         $ie.Quit()
  68.     }    
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement