All Products
Search
Document Center

Simple Message Queue (formerly MNS):SendMessage

Last Updated:Mar 11, 2026

Sends a message to a specified queue.

Usage notes

  • Base64-encode the message body before sending. Messages with non-Base64-encoded bodies or unsupported characters cause request failures.

  • A message sent without a delay is immediately available for consumption. To defer consumption, set DelaySeconds to a value greater than 0. The message enters the Delayed status and transitions to Active after the specified delay period.

  • If you set DelaySeconds at both the message level and the queue level, the message-level value takes precedence.

Authorization

By default, only an Alibaba Cloud account can call this operation. To allow a RAM user to call this operation, grant the required permissions. For more information, see Permission policies and examples.

NameValue
APISendMessage
Actionmns:SendMessage
Resourceacs:mns:$region:$accountid:/queues/$queueName/messages

Request syntax

POST /queues/$queueName/messages HTTP/1.1
Host: $AccountId.mns.<region>.aliyuncs.com
Date: <date>
Content-Length: <content-length>
Content-Type: text/xml;charset=utf-8
x-mns-version: 2015-06-06
Authorization: MNS <AccessKeyId>:<Signature>
<?xml version="1.0" encoding="UTF-8"?>
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MessageBody>Base64-encoded message content</MessageBody>
    <DelaySeconds>0</DelaySeconds>
    <Priority>1</Priority>
</Message>

Operation-specific request headers: None.

Request body parameters

ParameterTypeRequiredExampleDescription
MessageBodyStringYesThis is a test messageThe body of the message. Base64-encode this value before sending.
DelaySecondsIntegerNo60The period in seconds before the message becomes available for consumption. Valid values: 0 to 604800. Default value: 0.

Response syntax

HTTP/1.1 201 Created
Content-Length: <content-length>
Content-Type: text/xml;charset=utf-8
x-mns-request-id: <request-id>
x-mns-version: 2015-06-06
<?xml version="1.0" encoding="UTF-8"?>
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MessageId>5F290C926D472878-2-14D9529A8FA-20000****</MessageId>
    <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6****</MessageBodyMD5>
    <ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
</Message>

Operation-specific response headers: None.

Response body parameters

ParameterTypeExampleDescription
MessageIdString5F290C926D472878-2-14D9529A8FA-20000****The unique ID of the message in the queue.
MessageBodyMD5StringC5DD56A39F5F7BB8B3337C6D11B6****The MD5 hash of the message body. Use this value to verify message integrity.
ReceiptHandleString1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==The receipt handle of the message. Returned only for delayed messages.

Examples

Send a delayed message

The following request sends a message with a 60-second delay to a queue. The message enters the Delayed status and becomes consumable after 60 seconds.

Request

POST /queues/$queueName/messages HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Wed, 18 Mar 2012 12:00:00 GMT
Content-Length:500
Content-Type:text/xml;charset=utf-8
x-mns-version: 2015-06-06
Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEX****
<?xml version="1.0" encoding="UTF-8"?>
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MessageBody>This is a test message</MessageBody>
    <DelaySeconds>60</DelaySeconds>
    <Priority>1</Priority>
</Message>

Response

HTTP/1.1 201 Created
Content-Length:120
Content-Type:text/xml;charset=utf-8
x-mns-request-id:512B2A634403E52B1956****
x-mns-version: 2015-06-06
<?xml version="1.0" encoding="UTF-8"?>
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MessageId>5F290C926D472878-2-14D9529****-200000001</MessageId>
    <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6****</MessageBodyMD5>
    <ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
</Message>

Error codes

The following table lists error codes specific to this operation. For common error codes, see Common error codes.

Error codeError messageHTTP status codeDescriptionSolution
QueueNotExistThe queue name you provided is not exist.404The specified queue does not exist.Verify the queue name and create the queue if it does not exist.
MalformedXMLThe XML you provided was not well-formed.400The request body contains invalid XML.Check the XML format and make sure it conforms to the request syntax.
InvalidArgumentThe value of Element should between Low and High seconds/bytes.400A parameter value is out of range.Check that DelaySeconds is between 0 and 604800, and that all parameter values are within their valid ranges.

See also