How to publish message directly to a US phone number?

0

I have been using the boto3 sns client to publish messages to phone numbers and they are working for non US phone numbers but they do not work for US phone numbers. I have specified the origination numbers but they do not seem to be working.

sns_client = boto3.client("sns", region_name="us-west-2") try: response_sns = sns_client.publish( PhoneNumber=PhoneNo, Message="Hello," + first_name + ". Your OTP is " + str(OTP) + ".", MessageAttributes={ "AWS.SNS.SMS.SMSType": { "DataType": "String", "StringValue": "Transactional", }, "AWS.MM.SMS.OriginationNumber": { "DataType": "String", "StringValue": "+120******", }, }, ) print(response_sns) except Exception as e: print("could not send sms") print(e)

The use of US phone numbers doesnot show any errors. just that the messages are not received.

已提問 3 個月前檢視次數 199 次
1 個回答
2

There are couple of things that you need to setup before getting this code worked and send message.

  1. Do you have Origination number setup(from SNS console), if not then you need to set that up first.
  2. Refer Adding and verifying phone numbers in the SMS sandbox and Origination numbers for more details. Once you have origination number set up, then you can test text messaging from SNS console first.
  3. Once you verify this through SNS console, your code should work as well.

I understand, API call doesn't give the error when you try to attempt to send message but if you'd try doing it through SNS, there you'll get error message as something like below:

Enter image description here

Hope this explains. Comment here if you have additional questions. Happy to help.

profile pictureAWS
專家
已回答 3 個月前
  • Do you have any query furthermore, happy to assist.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南