Gmail.ps
Gmail.ps copied to clipboard
Message body missing?
Import-Module ".\gmail.ps\Gmail.ps.psm1"
Add-Type -Path '.\gmail.ps\AE.Net.Mail.dll'
$userName = "[YOUREMAIL]"
$password = "[YOURPASSWORD]"
$nc = New-Object System.Net.NetworkCredential($userName, $password);
$creds = new-object PSCredential($nc.UserName, (ConvertTo-SecureString $nc.Password -AsPlainText -Force))
Invoke-GmailSession -credential $creds -ScriptBlock {
param($gmail)
$msgs = $gmail | Get-Mailbox | Get-Message -unread
foreach($msg in $msgs)
{
$msg.From
$msg.Body
}
}
I'm receiving blanks /null for $msg.Body even though there is content within the bodies in gmail.
Solved it, the Prefetch option is not well documented.
Prefetch is usually used to just grab headers and not body content (in the code it passes !Prefetch into the HeadersOnly parameter on the GetMessage command. Which results in the body not being retrurned.
to fix it, I just added -prefetch on this line:
$msgs = $gmail | Get-Mailbox | Get-Message -unread -prefetch