All Products
Search
Document Center

Short Message Service:SendMessageWithTemplate

Last Updated:Dec 11, 2025

Sends a message to the Chinese mainland by using a message template.

Operation description

Usage notes

You can call the SendMessageWithTemplate operation to send messages only 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 mobile phone number to which the message is sent. You must add the country code to the beginning of the mobile phone number. Example: 861503871****.

For more information, see Dialing codes.

861503871****

From

string

Yes

The signature. To query the signature, log on to the Short Message Service (SMS) console and navigate to the Signatures tab of the Go China page.

Alicloud321

TemplateCode

string

Yes

The code of the message template. To query the code, log on to the SMS console and navigate to the Templates tab of the Go China page.

SMS_****

TemplateParam

string

No

The value of the variable in the message template. If a variable exists in the template, the parameter is required.

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

SmsUpExtendCode

string

No

The extension code of the MO message.

90999

ValidityPeriod

integer

No

The validity period of the message.

1

ChannelId

string

No

The ID of the channel.

5739

Response elements

Element

Type

Description

Example

object

ResponseCode

string

The status code of the delivery request.

OK

NumberDetail

object

The details about the mobile phone number of the recipient.

Carrier

string

The carrier that owns the mobile phone number.

China Mobile

Region

string

The region to which the mobile phone number belongs.

Nanjing, Jiangsu

Country

string

The country to which the mobile phone number belongs.

China

ResponseDescription

string

The description of the delivery request status.

The SMS Send Request was accepted

Segments

string

The number of messages that incurred fees.

1

To

string

The mobile phone number to which the message was sent. The dialing code was added to the beginning of the mobile phone number. Example: 861503871****.

861503871****

MessageId

string

The ID of the message.

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

RequestId

string

The ID of the request.

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.