Skip to content Skip to sidebar Skip to footer

How To Send An Sms With Custom Sender Id With Amazon Sns And Python And Boto3

The documentation suggests to use message attributes for that but I can't seem to figure out what attribute name to use. This works so far: sns = boto3.client('sns', region_name='e

Solution 1:

The sender id must be 1-11 alpha-numeric characters, no spaces; for example:

  • THISISME - ✅
  • TestForSO - ✅
  • StackOverflow - 🛑 (too long. max 11 chars)
  • Some one - 🛑 (no spaces)

As others mentioned, the sender id customization depends on the country / cellular provider so make sure to test it.

Example snippet

import boto3

access_key = '....'
secret = '....'
region = "us-east-1"number = '+972...<your number>'

sender_id = 'TestForSO'
sms_message = 'Your code: 123456'

sns = boto3.client('sns', aws_access_key_id=access_key, aws_secret_access_key=secret, region_name=region)
sns.publish(PhoneNumber=number, Message=sms_message, MessageAttributes={'AWS.SNS.SMS.SenderID': {'DataType': 'String', 'StringValue': sender_id}, 'AWS.SNS.SMS.SMSType': {'DataType': 'String', 'StringValue': 'Promotional'}})

enter image description here

Solution 2:

Check if your destination country supports sender IDs

http://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html

Solution 3:

As noted by Adam Owczarczyk, some countries don't allow you to transmit a sender ID in a text message. The API will take your number and replace it with a string in this case to allow your message to get delivered. Attempting to work around it usually just gets the number blacklisted. You can test this by entering a short descriptive string for your tester ID, and seeing if that gets through.

Post a Comment for "How To Send An Sms With Custom Sender Id With Amazon Sns And Python And Boto3"