Skip to main content

Message Attachments

Message attachments are handled by the message command group. Use this for files or inline images that are attached to a Teams chat or channel message. Use teams file only when you want to manage the channel file library directly.

Send inline images

Inline images are uploaded as Teams hosted content and are rendered in the message body.

teams message send --chat "$CHAT_ID" --image ./screenshot.png --output json
teams message send \
--team "$TEAM_ID" \
--channel "$CHANNEL_ID" \
--body "Screenshot attached" \
--image ./screenshot.png \
--output json

Each inline image must be 3 MB or smaller.

Send file attachments

File attachments are uploaded first, then referenced from the Teams message. Chat attachments are stored in the sender's OneDrive Microsoft Teams Chat Files folder. Channel attachments are stored in the team's SharePoint-backed files area.

teams message send --chat "$CHAT_ID" --body "Report attached" --attach ./report.pdf --output json
teams message send \
--team "$TEAM_ID" \
--channel "$CHANNEL_ID" \
--body "Logs attached" \
--attach ./logs.zip \
--output json

File attachments use Microsoft Graph's simple-upload path and are limited to 250 MB per file.

Reply to channel messages with attachments

Channel replies support the same --image and --attach flags as top-level messages.

teams message reply \
--team "$TEAM_ID" \
--channel "$CHANNEL_ID" \
--message "$MESSAGE_ID" \
--body "Adding the trace" \
--attach ./trace.txt \
--image ./detail.png \
--output json

List attachments

Use message get --with-attachments when you want a channel message payload and attachment metadata together.

teams message get --team "$TEAM_ID" --channel "$CHANNEL_ID" "$MESSAGE_ID" --with-attachments --output json

Use message attachments list when an automation only needs attachment metadata.

teams message attachments list --chat "$CHAT_ID" "$MESSAGE_ID" --output json
teams message attachments list \
--team "$TEAM_ID" \
--channel "$CHANNEL_ID" \
--reply "$REPLY_ID" \
"$MESSAGE_ID" \
--output json

Download attachments

Download all attachments into a directory:

teams message attachments download --chat "$CHAT_ID" "$MESSAGE_ID" --dir ./assets --output json

Download one attachment by index:

teams message attachments download --chat "$CHAT_ID" "$MESSAGE_ID" --index 0 --path ./image.png --output json

Write bytes to stdout when the surrounding script handles the destination:

teams message attachments download --chat "$CHAT_ID" "$MESSAGE_ID" --index 0 --path - > image.png

Required scopes

Inline hosted-content images use the same message permissions as reading or sending the message. File attachments require additional file permissions:

OperationDelegated scope
Read inline imagesSame message-read scope
Download file attachmentsFiles.Read.All
Send chat file attachmentsFiles.ReadWrite
Send channel file attachmentsFiles.ReadWrite.All

Add scopes to the profile that needs the capability, then refresh the token:

[profiles.attachments]
tenant_id = "common"
scopes = "User.Read Chat.ReadWrite ChannelMessage.Send ChannelMessage.Read.All Files.Read.All Files.ReadWrite Files.ReadWrite.All offline_access"
teams auth refresh --profile attachments

If the tenant requires admin consent, generate a scoped consent URL first:

teams auth consent-url --profile attachments