DirectMail SingSendMail not working

拥有回忆 提交于 2019-12-11 07:05:03

问题


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:


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



来源:https://stackoverflow.com/questions/51955706/directmail-singsendmail-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!