在我们的应用程序中,我们需要通过电子邮件向用户发送各种事件触发器的通知。
如果我以“我”的身份发送当前用户,我可以发送电子邮件,但尝试以另一个用户帐户发送会返回一条错误消息,如果通知不是用户自己发送的并且可能包含我们的信息,我会更喜欢它不想在已发送文件夹中浮动。
什么工作:
await graphClient.Me.SendMail(email, SaveToSentItems: false).Request().PostAsync();
Run Code Online (Sandbox Code Playgroud)
什么不起作用:
string FromUserEmail = "notifications@contoso.com";
await graphClient.Users[FromUserEmail].SendMail(email, SaveToSentItems: false).Request().PostAsync();
Run Code Online (Sandbox Code Playgroud)
还尝试直接使用用户对象 id:
await graphClient.Users["cd8cc59c-0815-46ed-aa45-4d46c8a89d72"].SendMail(email, SaveToSentItems: false).Request().PostAsync();
Run Code Online (Sandbox Code Playgroud)
我的应用程序有权将 Graph APISend mail as any user启用并由所有者/管理员授予“ ”。
API返回的错误信息:
代码:ErrorFolderNotFound 消息:在存储中找不到指定的文件夹。
我认为这个错误可能是因为通知帐户没有发送文件夹,所以我将该SaveToSentItems值设置为 false,但我仍然收到相同的错误。
我需要检查帐户本身是否有任何设置以允许应用程序在此帐户上发送邮件,或者这应该有效吗?
我在这里查看了文档:https : //developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_sendmail
这似乎支持我正在尝试做的事情,但没有引用任何文件夹,除了我告诉 API 无论如何不要保存的已发送项目文件夹。
我们不打算在这里冒充任何实际用户,只是从该特定帐户的应用程序内发送通知电子邮件(我知道这在技术上是冒充,但不是真实实体)。
我已经将基于 Identity Server 的项目从原始的 Identity Server 4 升级到Duende 的 Identity Server 6。升级似乎有效,但我必须删除一些现有代码才能使其正常工作。
这是我们以前的配置Startup.cs
services.AddIdentityServer()
.AddOperationalStore(options => {
options.RedisConnectionString = Configuration.GetConnectionString("Redis");
options.Db = 1;
})
.AddRedisCaching(options => {
options.RedisConnectionString = Configuration.GetConnectionString("Redis");
options.KeyPrefix = "custom_prefix";
})
.AddSigningCredential(new X509Certificate2(Path.Combine(HostingEnvironment.WebRootPath, "secretauth.pfx"), "secret_key"))
.AddUserStore() // Custom User Store
.AddResourceStore<CustomResourceStore>()
.AddClientStore<CustomClientStore>();
Run Code Online (Sandbox Code Playgroud)
之前的版本使用了IdentityServer4.Contrib.RedisStore,从 Identity Server 6 开始我们不再可用。
这意味着我们的新实现没有为会话数据添加 Redis 缓存的选项,而且我看不到可能提供该功能的 Duende 相关 nuget 包。
留给我们的只有这个;
services.AddIdentityServer(options =>
{
options.LicenseKey = Configuration.GetValue<string>(key: "Duende.IdentityServer:licenseKey");
})
.AddUserStore() // Custom User Store
.AddClientStore<CustomClientStore>()
.AddResourceStore<CustomResourceStore>();
Run Code Online (Sandbox Code Playgroud)
我是否在某个地方缺少一个可能有用的 Nuget …