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.

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.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ