英文:
How to send an email through a shared mailbox using Microsoft.Graph.Core
问题
抱歉,我只能翻译您提供的文本,不能提供代码的翻译。以下是翻译好的内容:
我有一个由MSAL保护的应用程序。我想通过经过身份验证的用户访问的共享邮箱发送电子邮件。
尝试发送电子邮件时,我的IDE会将下面的代码突出显示为错误:“Delete,应该有方法或事件”。
await graphClient.Users["test@test.com"].SendMail(message, true).Request().PostAsync();
所有在线示例都使用类似的代码,所以我很难看出问题在哪里。
我的项目引用了 Microsoft.Graph.Core 3.0.0。
英文:
I have an application that is secured by MSAL. I want to send an email through a shared mailbox that the authenticated user has access to.
When trying to sent the email, my IDE highlights the code below with the error "Delete, method or event expected".
await graphClient.Users["test@test.com"].SendMail(message, true).Request().PostAsync();
All online examples use similar code, so I'm struggling to see what is wrong with it.
My project has Microsoft.Graph.Core 3.0.0 referenced.
答案1
得分: 0
抱歉,我只能为您提供中文翻译。以下是您提供的内容的中文翻译:
"看起来你正在使用基于 Kiota 的 SDK,它已经移除了 Request 方法,并且还有许多其他更改,这意味着你在看的示例可能是基于之前版本(如 2.x)的,将无法工作。
在基于 Kiota 的 SDK 中,你需要使用 SendMailPostRequestBody 来控制是否保存到已发送项目,这作为 Send 方法的一个参数可用,例如:
var requestBody = new Microsoft.Graph.Me.SendMail.SendMailPostRequestBody
{
Message = new Message
{
Subject = "午餐见面吗?",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "新餐厅已开业。",
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "frannis@contoso.onmicrosoft.com",
},
},
},
CcRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "danas@contoso.onmicrosoft.com",
},
},
},
},
SaveToSentItems = true,
};
await graphClient.Users["test@test.com"].SendMail.PostAsync(requestBody);
"
英文:
Its looks like your using the Kiota based SDK which have removed the Request method and also has a number of other changes that mean the examples your looking at which used the previous version (eg 2.x) won't work.
With the Kiota based SDK you need to use the SendMailPostRequestBody to control the SaveToSentItems as that availble as a parameter of the Send Method eg
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
var requestBody = new Microsoft.Graph.Me.SendMail.SendMailPostRequestBody
{
Message = new Message
{
Subject = "Meet for lunch?",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "The new cafeteria is open.",
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "frannis@contoso.onmicrosoft.com",
},
},
},
CcRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "danas@contoso.onmicrosoft.com",
},
},
},
},
SaveToSentItems = true,
};
await graphClient.Users["test@test.com"].SendMail.PostAsync(requestBody);
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论