PoshCode Logo PowerShell Code Repository

mari07031986 by marimuthu 11 weeks ago (modification of post by greg zakharov view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6725"></script>download | new post

Not for regular use, this is just a demo with using COM object to check new letters on gmail.

  1. function Check-NewGmail {
  2.   param(
  3.     [String]$Email = (Read-Host "Enter your email"),    
  4.     [Security.SecureString]$Password = (Read-Host "Enter email password" -as)
  5.   )
  6.  
  7.   function str([Security.SecureString]$s) {
  8.     return [Runtime.InteropServices.Marshal]::PtrToStringAuto(
  9.       [Runtime.InteropServices.Marshal]::SecureStringToBSTR($s)
  10.     )
  11.   }
  12.   $com = New-Object -com MSXML2.XMLHTTP.3.0
  13.   $com.open('GET', $('https://' + $Email + ':' + `
  14.              (str $Password) + '@mail.google.com/mail/feed/atom'), $false)
  15.   $com.setRequestHeader('Content-Type', 'application/x-www-from-urlcoded')
  16.   $com.send()
  17.  
  18.   $com.responseText -match 'fullcount>\d+' | Out-Null; $res = ($matches[0] -split '>')[1]
  19.   Write-Host You have $res new letter`(s`).
  20. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me