问题描述
我正在使用从NuGet(1.2)下载的Microsoft Graph SDK.我使用ADAL对Azure AD进行身份验证.
I am using the Microsoft Graph SDK as downloaded from NuGet (1.2). I authenticate to Azure AD (using ADAL).
我正在使用客户端凭据"流(未作为任何特定用户进行身份验证),并且正在使用应用程序权限"角色来访问资源.
I am using Client Credentials flow (not authenticated as any particular user) and am using Application Permission roles to access resources.
我们将使用一个别名来建立一个服务邮箱.别名被提供给客户端.因此,他们通过电子邮件发送了一个具有有意义名称的地址.
We are going to set up one service mailbox with a bunch of aliases. The aliases are given to the clients. This is so they are emailing an address that has a meaningful name to them.
我的应用程序将作为服务运行,并定期扫描此收件箱中的新电子邮件.它应该找到收件人"地址,并根据使用的别名将电子邮件归档到与该客户相关的位置.
My app will run as a service, and routinely scan new emails in this inbox. It should find the To address, and depending on what alias was used, file the email in a location relevant to that client.
我想要的资源是:GET /users/<id | userPrincipalName>/messages
但是,SDK中似乎没有针对它的方法.
However, there doesn't appear to be a method in the SDK for it.
我可以为此吸引用户:
IGraphServiceUsersCollectionPage filteredUsers =
graphApi.Users.Request()
.Filter("userPrincipalName eq '[email protected]'")
.GetAsync().Result;
当我遍历集合时,我可以看到用户具有消息"属性,但始终为空.
When I loop through the collection, I can see that the User has a 'Messages' property, but it is always null.
如果我使用HttpClient手动构建请求消息,则可以获得消息.
If I manually build a request message with HttpClient I can get the messages.
第二个问题是收件人属性始终是邮箱的userPrincipalName.如何获取发件人使用的别名?
The second problem is that the Recipient property is always the userPrincipalName of the mailbox. How can I get the alias that was used by the sender?
推荐答案
虽然可以成功获取用户集合,但是您必须提出另一个请求以接收消息.看起来像这样:
While you are able to get your collection of users successfully, you have to make another request to receive the messages. This would look something like:
IUserMessagesCollectionPage userMessages =
graphApi.Users["user_id"].Messages.Request()
.GetAsync().Result;
要回答第二个问题,目前您无法通过Graph API访问原始收件人,但是您可以 通过EWS进行此操作.这是因为您只能通过EWS检索SMTP邮件头.您可以阅读有关如何执行此操作的更多信息这里.
To answer your second question, at this time you cannot access the original recipient through the Graph API, but you can do this through EWS. This is due to the fact that you can only retrieve the SMTP message headers through EWS. You can read more about how to do this here.
如果您认为这对图表有价值,那么我建议您将其发布到我们的 UserVoice .
If this is something you believe is valuable to you in the Graph, I would encourage you to post it in our UserVoice.
如果要以文件形式获取电子邮件,则可以通过SDK轻松获取正文(以字节为单位):
If you want to get the email as a file, you can simply get the body as bytes through the SDK:
byte[] asBytes = Encoding.Unicode.GetBytes(message.Body.ToString());
这篇关于Microsoft Graph API SDK .NET问题使其他用户收到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!