L’une des autorisations suivantes est nécessaire pour appeler cette API. Pour plus d’informations, notamment sur la façon de choisir les autorisations, voir Autorisations.
Type d’autorisation
Autorisations (de celle qui offre le plus de privilèges à celle qui en offre le moins)
Déléguée (compte professionnel ou scolaire)
Mail.ReadWrite
Déléguée (compte Microsoft personnel)
Mail.ReadWrite
Application
Mail.ReadWrite
Requête HTTP
POST /me/mailFolders/{id}/messages
POST /users/{id | userPrincipalName}/mailFolders/{id}/messages
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Message
{
ReceivedDateTime = DateTimeOffset.Parse("datetime-value"),
SentDateTime = DateTimeOffset.Parse("datetime-value"),
HasAttachments = true,
Subject = "subject-value",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "content-value",
},
BodyPreview = "bodyPreview-value",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.MailFolders["{mailFolder-id}"].Messages.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Message message = new Message();
OffsetDateTime receivedDateTime = OffsetDateTime.parse("datetime-value");
message.setReceivedDateTime(receivedDateTime);
OffsetDateTime sentDateTime = OffsetDateTime.parse("datetime-value");
message.setSentDateTime(sentDateTime);
message.setHasAttachments(true);
message.setSubject("subject-value");
ItemBody body = new ItemBody();
body.setContentType(BodyType.Text);
body.setContent("content-value");
message.setBody(body);
message.setBodyPreview("bodyPreview-value");
Message result = graphClient.me().mailFolders().byMailFolderId("{mailFolder-id}").messages().post(message);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.message import Message
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.body_type import BodyType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Message(
received_date_time = "datetime-value",
sent_date_time = "datetime-value",
has_attachments = True,
subject = "subject-value",
body = ItemBody(
content_type = BodyType.Text,
content = "content-value",
),
body_preview = "bodyPreview-value",
)
result = await graph_client.me.mail_folders.by_mail_folder_id('mailFolder-id').messages.post(request_body)