All Products
Search
Document Center

Short Message Service:SendMessageWithTemplate

Last Updated:Oct 27, 2026

Sends a text message by using a message template. This operation supports sending text messages only to the Chinese mainland.

Operation description

Usage notes

The SendMessageWithTemplate operation only supports sending text messages to the Chinese mainland.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dysms:SendMessageWithTemplate

create

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

To

string

Yes

The phone number of the recipient. Format: country code + phone number. Example: 861503871****.

For more information about country codes, see Dialing codes.

861503871****

From

string

Yes

The sender identifier. Specify the name of the text message signature. You can log on to the Short Message Service console, choose Send to Chinese Mainland > Signatures, and view the signature name in the signature list.

Alicloud321

TemplateCode

string

Yes

The code of the text message template. You can log on to the Short Message Service console, choose Send to Chinese Mainland > Message Templates, and view the template code in the template list.

SMS_****

TemplateParam

string

No

The actual values of the variables in the text message template. This parameter is required if the template contains variables.

{"code":"1234","product":"ytx"}

SmsUpExtendCode

string

No

The extension code for upstream text messages.

90999

ValidityPeriod

integer

No

The validity period of the text message.

1

ChannelId

string

No

The channel ID.

5739

Response elements

Element

Type

Description

Example

object

ResponseCode

string

The submission status of the text message.

OK

NumberDetail

object

The details of the phone number.

Carrier

string

The carrier network to which the phone number belongs.

China Mobile

Region

string

The region to which the phone number belongs.

Nanjing, Jiangsu

Country

string

The country to which the phone number belongs.

China

ResponseDescription

string

The detailed description of the text message submission status.

The SMS Send Request was accepted

Segments

string

The number of billed text message segments.

1

To

string

The phone number of the recipient. Format: country code + phone number. Example: 861503871****.

861503871****

MessageId

string

The message ID.

1**************3

RequestId

string

The request ID.

F655A8D5-B967-440B-8683-DAD6FF8D23D6

Examples

Success response

JSON format

{
  "ResponseCode": "OK",
  "NumberDetail": {
    "Carrier": "China Mobile",
    "Region": "Nanjing, Jiangsu",
    "Country": "China"
  },
  "ResponseDescription": "The SMS Send Request was accepted",
  "Segments": "1",
  "To": "861503871****",
  "MessageId": "1**************3",
  "RequestId": "F655A8D5-B967-440B-8683-DAD6FF8D23D6"
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.