Gmail.ps icon indicating copy to clipboard operation
Gmail.ps copied to clipboard

Message body missing?

Open SPDEVGUY opened this issue 7 years ago • 1 comments

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.

SPDEVGUY avatar May 26 '17 18:05 SPDEVGUY

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

SPDEVGUY avatar May 26 '17 18:05 SPDEVGUY