*
Anmerkung: S/MIME-Nachrichtennutzlasten sind derzeit auf 4 MB beschränkt. Übermittlungsversuche, die diese Grenze überschreiten, führen zu einerHTTP 413 Request Entity Too Large Fehlermeldung.
Zum Aufrufen dieser API ist eine der folgenden Berechtigungen erforderlich. Weitere Informationen, unter anderem zur Auswahl von Berechtigungen, finden Sie unter Berechtigungen.
Berechtigungstyp
Berechtigungen (von der Berechtigung mit den wenigsten Rechten zu der mit den meisten Rechten)
Delegiert (Geschäfts-, Schul- oder Unikonto)
Mail.ReadWrite
Delegiert (persönliches Microsoft-Konto)
Mail.ReadWrite
Anwendung
Mail.ReadWrite
HTTP-Anforderung
POST /me/messages
POST /users/{id|userPrincipalName}/messages
POST /me/mailFolders/{id}/messages
POST /users/{id | userPrincipalName}/mailFolders/{id}/messages
Die Art der Daten im Textkörper einer Entität. Erforderlich. Verwenden Sie application/json für ein JSON-Objekt und text/plain für MIME-Inhalt.
Anforderungstext
Geben Sie bei Verwendung des JSON-Formats eine JSON-Darstellung des Nachrichten-Objekts an.
Geben Sie bei der Angabe des Texts im MIME-Format den MIME-Inhalt mit den entsprechenden Internetnachrichtenkopfzeilen ("An", "CC", "BCC", "Betreff") an, die alle im Anforderungstext im base64-Format codiert sind.
Da die message-Ressource Erweiterungen unterstützt, können Sie den POST-Vorgang verwenden und während der Erstellung der Nachricht benutzerdefinierte Eigenschaften mit Ihren eigenen Daten hinzufügen.
Antwort
Bei erfolgreicher Ausführung der Methode werden der Antwortcode 201 Created und das message-Objekt im Antworttext zurückgegeben.
Wenn der Anforderungstext falsch formatierten MIME-Inhalt enthält, gibt diese Methode 400 Bad request sowie die folgende Fehlermeldung an: „Ungültige Base64-Zeichenfolge für MIME-Inhalt“.
Beispiele
Beispiel 1: Erstellen Sie einen neuen Nachrichtenentwurf im JSON-Format
POST https://graph.microsoft.com/v1.0/me/messages
Content-type: application/json
{
"subject":"Did you see last night's game?",
"importance":"Low",
"body":{
"contentType":"HTML",
"content":"They were <b>awesome</b>!"
},
"toRecipients":[
{
"emailAddress":{
"address":"AdeleV@contoso.com"
}
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Message
{
Subject = "Did you see last night's game?",
Importance = Importance.Low,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "They were <b>awesome</b>!",
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "AdeleV@contoso.com",
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Messages.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewMessage()
subject := "Did you see last night's game?"
requestBody.SetSubject(&subject)
importance := graphmodels.LOW_IMPORTANCE
requestBody.SetImportance(&importance)
body := graphmodels.NewItemBody()
contentType := graphmodels.HTML_BODYTYPE
body.SetContentType(&contentType)
content := "They were <b>awesome</b>!"
body.SetContent(&content)
requestBody.SetBody(body)
recipient := graphmodels.NewRecipient()
emailAddress := graphmodels.NewEmailAddress()
address := "AdeleV@contoso.com"
emailAddress.SetAddress(&address)
recipient.SetEmailAddress(emailAddress)
toRecipients := []graphmodels.Recipientable {
recipient,
}
requestBody.SetToRecipients(toRecipients)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
messages, err := graphClient.Me().Messages().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Message message = new Message();
message.setSubject("Did you see last night's game?");
message.setImportance(Importance.Low);
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("They were <b>awesome</b>!");
message.setBody(body);
LinkedList<Recipient> toRecipients = new LinkedList<Recipient>();
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("AdeleV@contoso.com");
recipient.setEmailAddress(emailAddress);
toRecipients.add(recipient);
message.setToRecipients(toRecipients);
Message result = graphClient.me().messages().post(message);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Message;
use Microsoft\Graph\Generated\Models\Importance;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\BodyType;
use Microsoft\Graph\Generated\Models\Recipient;
use Microsoft\Graph\Generated\Models\EmailAddress;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Message();
$requestBody->setSubject('Did you see last night\'s game?');
$requestBody->setImportance(new Importance('low'));
$body = new ItemBody();
$body->setContentType(new BodyType('hTML'));
$body->setContent('They were <b>awesome</b>!');
$requestBody->setBody($body);
$toRecipientsRecipient1 = new Recipient();
$toRecipientsRecipient1EmailAddress = new EmailAddress();
$toRecipientsRecipient1EmailAddress->setAddress('AdeleV@contoso.com');
$toRecipientsRecipient1->setEmailAddress($toRecipientsRecipient1EmailAddress);
$toRecipientsArray []= $toRecipientsRecipient1;
$requestBody->setToRecipients($toRecipientsArray);
$result = $graphServiceClient->me()->messages()->post($requestBody)->wait();
# 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.importance import Importance
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.body_type import BodyType
from msgraph.generated.models.recipient import Recipient
from msgraph.generated.models.email_address import EmailAddress
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Message(
subject = "Did you see last night's game?",
importance = Importance.Low,
body = ItemBody(
content_type = BodyType.Html,
content = "They were <b>awesome</b>!",
),
to_recipients = [
Recipient(
email_address = EmailAddress(
address = "AdeleV@contoso.com",
),
),
],
)
result = await graph_client.me.messages.post(request_body)
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Message
{
Subject = "9/8/2018: concert",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "The group represents Washington.",
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "AlexW@contoso.com",
},
},
},
InternetMessageHeaders = new List<InternetMessageHeader>
{
new InternetMessageHeader
{
Name = "x-custom-header-group-name",
Value = "Washington",
},
new InternetMessageHeader
{
Name = "x-custom-header-group-id",
Value = "WA001",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.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();
message.setSubject("9/8/2018: concert");
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("The group represents Washington.");
message.setBody(body);
LinkedList<Recipient> toRecipients = new LinkedList<Recipient>();
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("AlexW@contoso.com");
recipient.setEmailAddress(emailAddress);
toRecipients.add(recipient);
message.setToRecipients(toRecipients);
LinkedList<InternetMessageHeader> internetMessageHeaders = new LinkedList<InternetMessageHeader>();
InternetMessageHeader internetMessageHeader = new InternetMessageHeader();
internetMessageHeader.setName("x-custom-header-group-name");
internetMessageHeader.setValue("Washington");
internetMessageHeaders.add(internetMessageHeader);
InternetMessageHeader internetMessageHeader1 = new InternetMessageHeader();
internetMessageHeader1.setName("x-custom-header-group-id");
internetMessageHeader1.setValue("WA001");
internetMessageHeaders.add(internetMessageHeader1);
message.setInternetMessageHeaders(internetMessageHeaders);
Message result = graphClient.me().messages().post(message);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Message;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\BodyType;
use Microsoft\Graph\Generated\Models\Recipient;
use Microsoft\Graph\Generated\Models\EmailAddress;
use Microsoft\Graph\Generated\Models\InternetMessageHeader;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Message();
$requestBody->setSubject('9/8/2018: concert');
$body = new ItemBody();
$body->setContentType(new BodyType('hTML'));
$body->setContent('The group represents Washington.');
$requestBody->setBody($body);
$toRecipientsRecipient1 = new Recipient();
$toRecipientsRecipient1EmailAddress = new EmailAddress();
$toRecipientsRecipient1EmailAddress->setAddress('AlexW@contoso.com');
$toRecipientsRecipient1->setEmailAddress($toRecipientsRecipient1EmailAddress);
$toRecipientsArray []= $toRecipientsRecipient1;
$requestBody->setToRecipients($toRecipientsArray);
$internetMessageHeadersInternetMessageHeader1 = new InternetMessageHeader();
$internetMessageHeadersInternetMessageHeader1->setName('x-custom-header-group-name');
$internetMessageHeadersInternetMessageHeader1->setValue('Washington');
$internetMessageHeadersArray []= $internetMessageHeadersInternetMessageHeader1;
$internetMessageHeadersInternetMessageHeader2 = new InternetMessageHeader();
$internetMessageHeadersInternetMessageHeader2->setName('x-custom-header-group-id');
$internetMessageHeadersInternetMessageHeader2->setValue('WA001');
$internetMessageHeadersArray []= $internetMessageHeadersInternetMessageHeader2;
$requestBody->setInternetMessageHeaders($internetMessageHeadersArray);
$result = $graphServiceClient->me()->messages()->post($requestBody)->wait();
# 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
from msgraph.generated.models.recipient import Recipient
from msgraph.generated.models.email_address import EmailAddress
from msgraph.generated.models.internet_message_header import InternetMessageHeader
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Message(
subject = "9/8/2018: concert",
body = ItemBody(
content_type = BodyType.Html,
content = "The group represents Washington.",
),
to_recipients = [
Recipient(
email_address = EmailAddress(
address = "AlexW@contoso.com",
),
),
],
internet_message_headers = [
InternetMessageHeader(
name = "x-custom-header-group-name",
value = "Washington",
),
InternetMessageHeader(
name = "x-custom-header-group-id",
value = "WA001",
),
],
)
result = await graph_client.me.messages.post(request_body)
Geben Sie im Anforderungstext eine JSON-Darstellung des message-Objekts an.
Antwort
Das folgende Beispiel zeigt die Antwort. Hinweis: Kopfzeilen von Internetnachrichten werden standardmäßig nicht in einer POST-Antwort wiedergegeben. Das hier gezeigte Antwortobjekt ist möglicherweise aus Platzgründen abgeschnitten. Von einem tatsächlichen Aufruf werden alle Eigenschaften zurückgegeben.
POST https://graph.microsoft.com/v1.0/me/messages
Content-type: text/plain
Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...
Import-Module Microsoft.Graph.Mail
$params = Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...
# A UPN can also be used as -UserId.
New-MgUserMessage -UserId $userId -BodyParameter $params