Elija el permiso o los permisos marcados como con privilegios mínimos para esta API. Use un permiso o permisos con privilegios superiores solo si la aplicación lo requiere. Para obtener más información sobre los permisos delegados y de aplicación, consulte Tipos de permisos. Para obtener más información sobre estos permisos, consulte la referencia de permisos.
Tipo de permiso
Permisos con privilegios mínimos
Permisos con privilegios más altos
Delegado (cuenta profesional o educativa)
Mail.ReadWrite
No disponible.
Delegado (cuenta personal de Microsoft)
Mail.ReadWrite
No disponible.
Aplicación
Mail.ReadWrite
No disponible.
Solicitud HTTP
POST /me/messages/{id}/attachments
POST /users/{id | userPrincipalName}/messages/{id}/attachments
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new FileAttachment
{
OdataType = "microsoft.graph.fileAttachment",
Name = "name-value",
ContentType = "contentType-value",
IsInline = false,
ContentLocation = "contentLocation-value",
ContentBytes = Convert.FromBase64String("base64-contentBytes-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.Messages["{message-id}"].Attachments.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.NewAttachment()
name := "name-value"
requestBody.SetName(&name)
contentType := "contentType-value"
requestBody.SetContentType(&contentType)
isInline := false
requestBody.SetIsInline(&isInline)
contentLocation := "contentLocation-value"
requestBody.SetContentLocation(&contentLocation)
contentBytes := []byte("base64-contentBytes-value")
requestBody.SetContentBytes(&contentBytes)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
attachments, err := graphClient.Me().Messages().ByMessageId("message-id").Attachments().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
FileAttachment attachment = new FileAttachment();
attachment.setOdataType("microsoft.graph.fileAttachment");
attachment.setName("name-value");
attachment.setContentType("contentType-value");
attachment.setIsInline(false);
attachment.setContentLocation("contentLocation-value");
byte[] contentBytes = Base64.getDecoder().decode("base64-contentBytes-value");
attachment.setContentBytes(contentBytes);
Attachment result = graphClient.me().messages().byMessageId("{message-id}").attachments().post(attachment);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.file_attachment import FileAttachment
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = FileAttachment(
odata_type = "microsoft.graph.fileAttachment",
name = "name-value",
content_type = "contentType-value",
is_inline = False,
content_location = "contentLocation-value",
content_bytes = base64.urlsafe_b64decode("base64-contentBytes-value"),
)
result = await graph_client.me.messages.by_message_id('message-id').attachments.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 Attachment
{
OdataType = "#Microsoft.OutlookServices.ItemAttachment",
Name = "name-value",
AdditionalData = new Dictionary<string, object>
{
{
"item" , new Message
{
OdataType = "microsoft.graph.message",
}
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Events["{event-id}"].Attachments.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.NewAttachment()
name := "name-value"
requestBody.SetName(&name)
additionalData := map[string]interface{}{
item := graphmodels.NewMessage()
requestBody.SetItem(item)
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
attachments, err := graphClient.Me().Events().ByEventId("event-id").Attachments().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Attachment attachment = new Attachment();
attachment.setOdataType("#Microsoft.OutlookServices.ItemAttachment");
attachment.setName("name-value");
HashMap<String, Object> additionalData = new HashMap<String, Object>();
Message item = new Message();
item.setOdataType("microsoft.graph.message");
additionalData.put("item", item);
attachment.setAdditionalData(additionalData);
Attachment result = graphClient.me().events().byEventId("{event-id}").attachments().post(attachment);
Import-Module Microsoft.Graph.Calendar
$params = @{
"@odata.type" = "#Microsoft.OutlookServices.ItemAttachment"
name = "name-value"
item = @{
"@odata.type" = "microsoft.graph.message"
}
}
# A UPN can also be used as -UserId.
New-MgUserEventAttachment -UserId $userId -EventId $eventId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.attachment import Attachment
from msgraph.generated.models.message import Message
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Attachment(
odata_type = "#Microsoft.OutlookServices.ItemAttachment",
name = "name-value",
additional_data = {
"item" : {
"@odata_type" : "microsoft.graph.message",
},
}
)
result = await graph_client.me.events.by_event_id('event-id').attachments.post(request_body)
En el ejemplo siguiente se muestra la respuesta. Nota: Es posible que el objeto de respuesta que aparezca aquí esté truncado para abreviar. Todas las propiedades se devolverán desde una llamada real.