使用Powershell阅读Gmail电子邮件

时间:2017-02-22 08:53:31

标签: powershell scripting gmail

我们希望根据我们通过电子邮件从我们网络中的设备通过不同管理系统收到的电子邮件自动执行操作

我尝试过这个小脚本,但它只列出主题,而不是正文

# load rss-feed
$webclient = new-object System.Net.WebClient

# access the rss-feed
$webclient.Credentials = new-object System.Net.NetworkCredential ("scominbox@domain", "Password")

# download the rss as xml
[xml]$xml= $webclient.DownloadString("https://mail.google.com/mail/feed/atom")

# display only sender name and message title as custom table
$format= @{Expression={$_.title};Label="Title"},@{Expression={$_.author.name};Label="Author"}

# display the table
$xml.feed.entry | format-table $format

如何阅读电子邮件?

2 个答案:

答案 0 :(得分:2)

根据this documentation,可以使用值formatfull定义raw

  

可选查询参数format string要返回的格式   消息。

     

可接受的值是:

"full": Returns the full email message data with body content parsed in the 
payload field; the raw field is not used. (default)
"raw": Returns the full email message data with body content in the raw field 
as a base64url encoded string; the payload field is not used. 

答案 1 :(得分:1)

请将#display下的代码更改为发件人姓名和邮件标题为自定义表格

为:

$format= @{Expression={$_.title};Label="Title"},
         @{Expression={$_.author.name};Label="Author"}, 
         @{Expression={$_.summary};Label="Body"}

在XML文件中,电子邮件正文保存在摘要标记下。

相关问题