SMS Text Messaging: “Delivers as a spam message.”

0

I have a custom Cognito Lambda function that generates a random code and sends it directly to a phone number.

try {
    if (!event.request.session || !event.request.session.length) {
         secretLoginCode = randomDigits(5).join("");  
      
      if ("phone_number" in event.request.userAttributes) {    
        const input = {
          // PublishInput
          PhoneNumber: event.request.userAttributes.phone_number,
          Message:
            "Ingresa a tu app con el siguiente código: " + secretLoginCode, // required
          Subject: "Tu código",       
          MessageAttributes: {
            // MessageAttributeMap
            "AWS.SNS.SMS.SMSType": {
              DataType: "String",
              StringValue: "Transactional",
            },
          },
  
        };  
        const command = new PublishCommand(input);
        const response = await snsClient.send(command);
      }   
    } else {     
      const previousChallenge = event.request.session.slice(-1)[0];
      secretLoginCode =
        previousChallenge.challengeMetadata.match(/CODE-(\d*)/)[1];
    }
    event.response.publicChallengeParameters = {
      email: event.request.userAttributes.email,
    };
    // Add the secret login code to the private challenge parameters
    // so it can be verified by the "Verify Auth Challenge Response" trigger
    event.response.privateChallengeParameters = { secretLoginCode };
    // Add the secret login code to the session so it is available
    // in a next invocation of the "Create Auth Challenge" trigger
    event.response.challengeMetadata = `CODE-${secretLoginCode}`;
    return event;
  } catch (error) {
    console.log(error);
    if (error instanceof MissingFieldError) {
      return {
        statusCode: 400,
        body: JSON.stringify(error.message),
      };
    }

    if (error instanceof JsonError) {
      return {
        statusCode: 400,
        body: JSON.stringify(error.message),
      };
    }
    return {
      statusCode: 500,
      body: JSON.stringify(error.message),
    };
  }
}

The text message is consistently being flagged as spam. How can I change this?

1 Answer
0

Hello Julian,

There are a few potential reasons why Amazon SNS may be marking your SMS text messages as spam:

  • Message Content: The content of your SMS messages may not match the template registered in the Dedicated Messaging Channel (DLT) portal. Carriers and providers may block messages if the content doesn't match the registered template or contains characters distinct from the template.
  • Message Length: If your SMS message exceeds the 140-byte size quota, Amazon SNS will split it into multiple messages. Very long messages or those with multi-byte characters can get split into several message parts, which may be flagged as spam by carriers.
  • SMS Sandbox: When you start using Amazon SNS to send SMS messages, your AWS account is initially in the SMS sandbox. While in the sandbox, you can only send SMS messages to verified destination phone numbers. Sending messages to unverified numbers may result in them being marked as spam.
  • Opt-Out List: Carriers may block messages if the recipient has opted out of receiving messages. You can check the opt-out list by running the following AWS CLI command: aws sns list-phone-numbers-opted-out
  • Delivery Logs: You can check the Amazon SNS delivery logs for any notifications from carriers about why the messages weren't delivered, such as "Phone has blocked SMS", "Blocked as spam by phone carrier", or "Phone carrier blocked this message".

To troubleshoot and resolve the issue, I recommend reviewing the content and length of your SMS messages, ensuring they match the registered template, and verifying the destination phone numbers. You can also check the SMS delivery logs for any carrier-specific feedback. If the issue persists, you may need to work with the carriers directly to resolve any spam-related concerns.

Make sure you follow the SMS best practices listed in the following documentation page: https://docs.aws.amazon.com/sns/latest/dg/channels-sms-best-practices.html

profile pictureAWS
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions