使用 Powershell 阅读 Gmail 邮件

3

我们希望能够根据来自网络设备中不同的管理系统发送的电子邮件自动执行操作。

我尝试了这个小脚本,但它只列出了邮件主题,而没有正文内容。

# 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

我该如何阅读电子邮件?

请不要交叉发布 - HBruijn
并不总是容易知道我们应该在哪个网站上发布我们的问题,所以你必须接受我们有时这样做是为了得到答案。 - Fredrik L
有更好的机制可以获得有用和高质量的答案: http://meta.stackexchange.com/a/64069/282031 - HBruijn
你可能想尝试使用Gmail API。 - Linda Lawton - DaImTo
3个回答

2
根据此文档,您可以定义format的值为fullraw:

Optional query parameters format string The format to return the message in.

Acceptable values are:

"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. 

谢谢尝试,但看起来那是针对 API 而不是我请求的 RSS 源。 - Fredrik L
哦,好的。那么这篇帖子可能会有所帮助:http://superuser.com/a/1181273/313985。 - 030

1
请仅将发送者姓名和消息标题作为自定义表格更改在#display下的代码。
$format= @{Expression={$_.title};Label="Title"},
         @{Expression={$_.author.name};Label="Author"}, 
         @{Expression={$_.summary};Label="Body"}

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

0

你可以使用:

$xml.feed.entry | Select *

它将以以下格式返回数据:

title           : 
summary         : Test body
link            : link
modified        : <date>
issued          : <date>
id              : <date>
author          : author
Name            : entry
LocalName       : entry
NamespaceURI    : http://purl.org/atom/ns#
Prefix          : 
NodeType        : Element
ParentNode      : feed
OwnerDocument   : #document
IsEmpty         : False
Attributes      : {}
HasAttributes   : False
SchemaInfo      : System.Xml.XmlName
InnerXml        : <OMITTED>
InnerText       : <OMITTED>
NextSibling     : 
PreviousSibling : modified
Value           : 
ChildNodes      : {title, summary, link, modified...}
FirstChild      : title
LastChild       : author
HasChildNodes   : True
IsReadOnly      : False
OuterXml        : <OMITTED>
BaseURI         : 
PreviousText    :

1
你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community
请提供一个更具体的示例,说明如何访问电子邮件正文。 - Dennis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接