DirectMail SingSendMail not working

2019-07-27 10:43发布

I am trying the singleSendMail API from Alibaba Cloud's DirectMail, the request looks something like this

https://xx.xxxx.com/?Action=SingleSendMail
&AccountName=test@example.com
&ReplyToAddress=true
&AddressType=1   
&ToAddress=test1@example.com
&Subject=Subject
&HtmlBody=<body><h2>Test</h2></body>

I get a 400 error MissingParameter

1条回答
We Are One
2楼-- · 2019-07-27 11:11

The Alibaba Cloud REST API has two sets of parameters plus the signature that you must include in your request.

Using Python as an example, you need to specify the public parameters as follows:

parameters = {}

# Add the DirectMail public request parameters
parameters["Format"] = "json"
parameters["AccessKeyId"] = credentials['AccessKey']
parameters["SignatureMethod"] = "HMAC-SHA1"
parameters["SignatureType"] = ""
parameters["SignatureVersion"] = "1.0"
parameters["SignatureNonce"] = get_uuid()
parameters["Timestamp"] = utc
parameters["Version"] = "2017-06-22"
parameters["RegionId"] = "ap-southeast-1"

The add the request parameters as follows. You will need to modify with your account information:

# Add parameters that are always set
parameters["Action"] = "SingleSendMail"
parameters["AddressType"] = "1"
parameters["ReplyToAddress"] = "true"

# Add the DirectMail API parameters
parameters["AccountName"] = dm_account
parameters["FromAlias"] = dm_alias
parameters["ToAddress"] = to_list
parameters["Subject"] = subject
parameters["HtmlBody"] = body
parameters["textBody"] = body_text

Then you will need to sign the request.

I wrote an article about Direct Mail and generating signatures with complete working source code in Python.

DirectMail REST API

查看更多
登录 后发表回答