To start sending SMS with C# you need to do the following:
- Create a 46elks account
- Purchase some credits. (The minimum purchase is 10 EUR, which is more than enough to get started.)
- Locate your API-credentials
Write your code with C#
Finally, it's time to write some C# code. Your code needs to be able to do the following:
- Define the content of the SMS [message], who will receive it [to] and who is the sender [from]
- Attach your API-username and API-password as BasicAuth to the HTTP Header.
- Send all this information to 46elks by an HTTP POST to https://api.46elks.com/a1/SMS
- Receive the response and handle any errors that might occur
Here's a code example:
And here's an example project file (tested in .NET Core 5.0):
To successfully send an SMS you need to set the following variables to your own values:
to(Your phone number).
- If you want you can also change
message, or leave it as it is.
Some tips on SMS parameter formatting:
The basic API request to send an SMS must contain these three key:value pairs: to, from and message.
toparameter should be the E.164 formatted number of the recipient.
messageparameter is the content of the SMS itself and can consist of numbers, letters, and other characters. You can even send emojis.
Exemple: How was this interview, 👌🏽 or 👎🏽 ?
If you are new to .NET Core, here are some additional pointers for you:
Download and Install .NET Core.
Open your terminal and run the following commands. The commands creates a program file, then adds a JSON package to the program file:
Use your favorite code editor to replace the content of Program.cs with the code example.
Edit the message, recipient, sender and the API authentication.
Now you can run your code. If you are using the terminal it will look like this:
If successful, you should expect a result similar to this:
You've just sent a text message with a text sender (i.e. not from a phone number). By doing this you can use SMS to remind customers of reservations, send confirmations of new orders, etc.
To send an SMS is the easiest way to get started with 46elks, but you can do so much more. For example you can receive SMS, automatically respond to an incoming SMS or handle voice calls. There are more C# examples at GitHub.
If you have any questions then get in touch, we love talking to our users!