Azure Communication Services – Sending an SMS

Goal:

This blog will go over how to send an SMS message to a cellular device using Azure Communication Services.

Creating an Azure Communication Service

From marketplace, search for Communication Services
Create a new resource
Scroll down to the Telephony and SMS section and go to the Phone Numbers
Click “GET” to create a new number, select the following settings for the “Features”
Set the following settings – you can special request numbers if need be
New Number is added to phone number instances
Get your connection string from the Keys tab

Creating the program:

Code setup – Install Azure.Communication.Sms Nuget Package

using Azure.Communication.Sms;

string connectionString = "endpoint=<YOUR ENDPOINT CONNECTION>"
SmsClient smsClient = new SmsClient(connectionString);

Sending an SMS from your toll-free number to any phone number

smsClient.Send(
    from: "<YOUR TOLL FREE NUMBER>",
    to: new string[] { "<ENTER A PHONE NUMBER +1>" },
    message: "Hello world! SMS works!",
    options: new SmsSendOptions(enableDeliveryReport: true)
    {
        Tag = "production"
    }
  );
Console App worked!
Message is received by the recipient