I am using AWS SDK to send the sms to the mobile number for sending OTP through the SMS.
The Issue here I am facing is the SMS are only being sent during the day time according to Indian Standard Time (9 am to 9pm). If I try to send SMS request to the AWS SNS endpoint after 9 pm, then it will send the message after 9 am the next day.
The code is as below.
String ACCESS_KEY = env.getProperty("aws.access.key");
String SECRET_KEY = env.getProperty("aws.secret.access.key");
// Above we get the access and secret access key as credentials for the user.
String otp = getRandomNumberString(); // generates an OTP number of 4 digit
AmazonSNSClient snsClient = new AmazonSNSClient(new BasicAWSCredentials(ACCESS_KEY,
SECRET_KEY));
String message = "Your Connect OTP for Login/Signup is: " + otp
+ ".\nNote: Please DO NOT SHARE THIS OTP with anyone.\nThanks";
String phoneNumber = "+91" + String.valueOf(mobile); // Ex: +91XXX4374XX
String messageID = sendSMSMessage(snsClient, message, phoneNumber);
// The definition of method named "sendSMSMessage" as above is written below in next code block
//definition of method named "sendSMSMessage"
public static String sendSMSMessage(AmazonSNSClient snsClient, String message, String phoneNumber) {
PublishResult result = snsClient
.publish(new PublishRequest().withMessage(message).withPhoneNumber(phoneNumber));
return result.getMessageId();
}