使用Microsoft.Graph.Core发送邮件到共享邮箱的方法

huangapple go评论51阅读模式
英文:

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 = &quot;Meet for lunch?&quot;,
		Body = new ItemBody
		{
			ContentType = BodyType.Text,
			Content = &quot;The new cafeteria is open.&quot;,
		},
		ToRecipients = new List&lt;Recipient&gt;
		{
			new Recipient
			{
				EmailAddress = new EmailAddress
				{
					Address = &quot;frannis@contoso.onmicrosoft.com&quot;,
				},
			},
		},
		CcRecipients = new List&lt;Recipient&gt;
		{
			new Recipient
			{
				EmailAddress = new EmailAddress
				{
					Address = &quot;danas@contoso.onmicrosoft.com&quot;,
				},
			},
		},
	},
	SaveToSentItems = true,
};
await graphClient.Users[&quot;test@test.com&quot;].SendMail.PostAsync(requestBody);

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月4日 23:56:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定