{"id":5065,"date":"2022-11-14T10:56:37","date_gmt":"2022-11-14T09:56:37","guid":{"rendered":"https:\/\/www.smsapi.com\/blog\/?p=5065"},"modified":"2024-01-29T14:57:59","modified_gmt":"2024-01-29T13:57:59","slug":"send-sms-c-library-sms-api","status":"publish","type":"post","link":"https:\/\/www.smsapi.com\/blog\/send-sms-c-library-sms-api\/","title":{"rendered":"Send SMS C# (library, code examples, open SMS API)"},"content":{"rendered":"\n<p><strong>How to send SMS messages from C#? Beginning with the basics, get to know our SMS API library, including sample code, practical advice, solutions to common problems, and more.<\/strong><\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Time for an introduction to another library for&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/en\/bulk-sms\" target=\"_blank\">bulk SMS gateway<\/a> for developers! In addition to <a rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/blog\/send-sms-with-php-library\/\" target=\"_blank\">PHP<\/a>, <a href=\"https:\/\/www.smsapi.com\/blog\/java-sms-guide-2023\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java<\/a>, <a href=\"https:\/\/www.smsapi.com\/blog\/javascript-sms-api-library-code-snippets-error-codes\/\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript<\/a> and <a href=\"https:\/\/www.smsapi.com\/blog\/send-sms-python-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a> discussed previously, <strong>SMSAPI also offers you implementation in C#<\/strong>. If this is a fit for your programming tastes \u2013 read on!<\/p>\n\n\n\n<p>The entire source code is made public on&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener nofollow\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\">SMSAPI GitHub<\/a>. There you will find two folders:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>smsapi<\/strong> \u2013 containing the production code you can use in your application. You&#8217;ll learn about its selected methods below.<\/li>\n\n\n\n<li><strong>smsapiTests<\/strong> \u2013 having unit tests which utilise the MSTest framework. Here you can find examples of the individual methods.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-smsapi-blog-2021-infobox infobox infobox--attention post-content--full-width\"><div class=\"infobox__icon\"><img decoding=\"async\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB2aWV3Qm94PSIwIDAgMTAgMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgY2xpcC1ydWxlPSJldmVub2RkIiB4bWw6c3BhY2U9InByZXNlcnZlIiB2ZXJzaW9uPSIxLjEiPgogIDxwYXRoIGlkPSJzdmdfMSIgc3R5bGU9ImZpbGw6IHJnYigxNywgMTkyLCAxMjgpOyBmaWxsLXJ1bGU6IG5vbnplcm87IiBkPSJtMi45MTk2NCwwbDQsMGwwLDRsLTEsN2wtMiwwbC0xLC03bDAsLTR6Ii8+CiAgPHBhdGggaWQ9InN2Z18yIiBzdHlsZT0iZmlsbDogcmdiKDE3LCAxOTIsIDEyOCk7IGZpbGwtcnVsZTogbm9uemVybzsiIGQ9Im03LjAwODM3LDE0YzAsMS4xMDUgLTAuODk1LDIgLTIsMmMtMS4xMDUsMCAtMiwtMC44OTUgLTIsLTJjMCwtMS4xMDUgMC44OTUsLTIgMiwtMmMxLjEwNSwwIDIsMC44OTUgMiwyeiIvPgo8L3N2Zz4K\"\/><\/div><div class=\"infobox__title\"><h4>Test SMSAPI<\/h4><\/div><div class=\"infobox__content\">\n<p>Still looking for the best SMS API? Create a test account and give it a shot!<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-primary\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.smsapi.com\/en\/signup\" target=\"_blank\" rel=\"noreferrer noopener\">Test SMSAPI<\/a><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n<p>The entire Library implements the API described in the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/docs\/\" target=\"_blank\">SMSAPI Documentation<\/a>. If you look there, you will undoubtedly find many analogies to the objects and methods in C#. For your convenience, we&#8217;ve illustrated it with numerous examples of how to send text messages. <\/p>\n\n\n\n<p>You can, of course, write your app from scratch in your chosen language, referring to the API directly. But it&#8217;s much simpler to copy and pa\u2026 pardon, use a ready-made solution. Let&#8217;s send SMS already!<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-secondary\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.smsapi.com\/en\/sms-api\" target=\"_blank\" rel=\"noreferrer noopener\">SMS API Libraries<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Create SMSAPI account<\/h2>\n\n\n\n<p>As with any other use of API services to handle SMS messages,&nbsp;<a href=\"https:\/\/www.smsapi.com\/en\/signup\" target=\"_blank\" rel=\"noreferrer noopener\">register<\/a> and then configure your account. You&#8217;ll need to provide the following data:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>basic info<\/strong> \u2013 e-mail (username), password (keep it private), phone number, first and last name;<\/li>\n\n\n\n<li><strong>company details<\/strong> \u2013 for invoicing;<\/li>\n\n\n\n<li><strong>SMS sender name<\/strong>&nbsp;\u2013 not mandatory, although useful;<\/li>\n\n\n\n<li><strong>additionally<\/strong> \u2013 an e-mail address for sending invoices and a contact phone number to your accounting department.<\/li>\n<\/ul>\n\n\n\n<p>After verification, we&#8217;ll activate your account. Start with charging your account with points for messaging! For more, see the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/blog\/do-it-yourself\/\" target=\"_blank\">SMSAPI Do It Yourself series<\/a> &#8211; a comprehensive guide to a professional SMS gateway. Here we&#8217;ll focus on programming SMS using C#.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-smsapi-blog wp-block-embed-smsapi-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"mde4GuZAgG\"><a href=\"https:\/\/www.smsapi.com\/blog\/do-it-yourself-customer-portal-walkthrough\/\">Do it yourself #01 &#8211; Customer Portal Walkthrough (video tutorial)<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Do it yourself #01 &#8211; Customer Portal Walkthrough (video tutorial)&#8221; &#8212; SMSAPI Blog\" src=\"https:\/\/www.smsapi.com\/blog\/do-it-yourself-customer-portal-walkthrough\/embed\/#?secret=h1fxNJYh3w#?secret=mde4GuZAgG\" data-secret=\"mde4GuZAgG\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">First steps in handling SMS campaign: configuration&nbsp;<\/h2>\n\n\n\n<p class=\"language-cpp\">Behind the scenes of our Library operates the&nbsp;<code>RestSharp<\/code>&nbsp;library that handles HTTP requests. It uses HTTP (GET, POST, PUT, DELETE) methods to handle all server communication and the&nbsp;text message campaign. Luckily for you, you don&#8217;t have to get into the details to use it. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Where and how to start, then?<\/h3>\n\n\n\n<p>As with most other projects: from the initialisation. The connection should be authorised using an API token. It is a string of 40 characters, which you can&nbsp;<a href=\"https:\/\/ssl.smsapi.com\/react\/oauth\/manage\" target=\"_blank\" rel=\"noreferrer noopener\">generate in the API Tokens (OAuth) tab<\/a> and, subsequently, use in Visual Studio:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>SMSApi.Api.IClient client = new SMSApi.Api.ClientOAuth(\"token\");<\/code><\/pre>\n\n\n\n<p class=\"language-cpp\">The <code>client<\/code>&nbsp;objects store data later used in authorisation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SMS message sending using C# methods<\/h2>\n\n\n\n<p>Once a client is set up, the Library works based on factories and actions, as shown in the example below. Here, a <strong>test message sent to a single recipient<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>var smsFactory = new SMSApi.Api.SMSFactory(client);\nSMSFactory.ActionSend(\"48111222333\", \"Hello world!\").Execute();<\/code><\/pre>\n\n\n\n<p class=\"language-cpp\">Three lines are enough to include the three basic stages of simple SMS handling: creating a client, creating a factory, and applying the right action. The server connection is handled within an object of the&nbsp;<code>Factory<\/code> class, which serves as a basis for numerous factories, including&nbsp;<code>SMSFactory<\/code>. These are responsible for the individual functions of the Library.<\/p>\n\n\n\n<p class=\"language-cpp\">On the other hand, methods of the Action type allow you to <strong>set up individual parameters<\/strong> of actions you want to perform. Method calls can be chained, starting from the Library and ending with execution (the&nbsp;<code>Execute()<\/code>&nbsp;method from the base class of all actions). For example, the following code functions in the same way as in the previous project:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>var smsFactory = new SMSApi.Api.SMSFactory(client);\nvar response = SMSFactory.ActionSend()\n      .SetTo(\"48111222333\")\n      .SetText(\"Hello world!\")\n      .Execute();<\/code><\/pre>\n\n\n\n<p class=\"language-cpp\">Responses to different queries to the API handle classes from the&nbsp;<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/tree\/master\/smsapi\/Api\/Response\"><code>Response<\/code><\/a> namespace. When ordering SMS sending in C#, use <code>Response.Status<\/code>&nbsp;(object type&nbsp;<code>response<\/code>&nbsp;from the example above). It has several useful properties.&nbsp;The <code>count<\/code>&nbsp;is the number of messages sent.&nbsp;The <code>list<\/code>&nbsp;is a list of their corresponding variables, including:&nbsp;<\/p>\n\n\n\n<ul class=\"language-cpp wp-block-list\">\n<li><code>ID<\/code>&nbsp;\u2013 a unique identifier in the SMSAPI system.<\/li>\n\n\n\n<li><code>Points<\/code>&nbsp;\u2013 cost expressed in the number of points deducted from your account.<\/li>\n\n\n\n<li><code>Number<\/code>&nbsp;\u2013 user phone number.<\/li>\n\n\n\n<li><code>Status<\/code>&nbsp;\u2013 delivery status (see&nbsp;the <a href=\"https:\/\/www.smsapi.com\/docs\/#17-delivery-statuses\" target=\"_blank\" rel=\"noreferrer noopener\">status list<\/a>&nbsp;in the Documentation).<\/li>\n<\/ul>\n\n\n\n<p class=\"language-cpp\">Other properties:&nbsp;<code>Message<\/code>,&nbsp;<code>Length<\/code>&nbsp;and&nbsp;<code>Parts<\/code>&nbsp;are, respectively, the content, number of characters used and parts of the text.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Send bulk SMS sending in C# code<\/h2>\n\n\n\n<p class=\"language-cpp\">The most basic function is sending the same text message to multiple recipients at once. Typing separate messages to each of your clients would simply be too work-intensive. By overloading&nbsp;the&nbsp;<code>ActionSend()<\/code>&nbsp;and&nbsp;<code>SetTo()<\/code>&nbsp;methods, this is handled by a minor code change.<\/p>\n\n\n\n<p class=\"language-cpp\">This is what sending identical messages to three recipients in one of two ways looks like&nbsp;<code>SMSFactory<\/code>&nbsp;and using method chaining from the&nbsp;<code>SMSSend<\/code> action:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>SMSFactory.ActionSend(\n      new&#91;]{\"48111222333\", \"48444555666\", \"48777888999\"},\n      \"Hello receivers!\")\n      .Execute();\nSMSFactory.ActionSend()\n      .SetTo(new&#91;]{\"48111222333\", \"48444555666\", \"48777888999\"})\n      .SetText(\"Hello again receivers!\")\n      .Execute();<\/code><\/pre>\n\n\n\n<p>In the Customer Portal, you&#8217;ll notice the ability to create recipient groups. The C# library allows you to use them to streamline bulk SMS campaign management. Another fragment showcases this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>SMSFactory.ActionSend()\n      .SetGroup(\"Group_name\")\n      .SetText(\"Hello group!\")\n      .Execute();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Automated SMS in C# \u2013 additional options<\/h2>\n\n\n\n<p class=\"language-cpp\">The&nbsp;<code>Action.SMSSend<\/code>&nbsp;class has a few more methods, which correspond to several useful functions of the Library. Let&#8217;s take a look at three of them.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to set an SMS sender name?<\/h3>\n\n\n\n<p class=\"language-cpp\"><code>SetSender(\"sender_name\")<\/code>&nbsp;sets the SMS sender name, i.e., <strong>the&nbsp;text displayed on the SMS recipient&#8217;s mobile phone instead of the number<\/strong>. This can be the brand or a product name, something characteristic that people will associate with your company. You must agree that it looks better than an unknown phone number. It also helps draw attention, especially since we receive many mobile notifications daily.<\/p>\n\n\n\n<p class=\"language-cpp\">You can create SMS sender names in the Customer Portal. From the programming perspective, these are handled by&nbsp;<code>SenderFactory<\/code>&nbsp;and the actions from the&nbsp;<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/tree\/master\/smsapi\/Api\/Action\/Sender\">Api\/Action\/Sender folder<\/a>.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Managing SMS sender names in the SMSAPI C# library<\/h3>\n\n\n\n<p class=\"language-cpp\">Let&#8217;s <strong>create SMS sender names in the Customer Portal<\/strong> and manage them using the code. Do it using&nbsp;<code>SenderFactory<\/code>&nbsp;and four actions: List, Add, SetDefault, and Delete. The simplest way is to handle them using the method from this factory. <\/p>\n\n\n\n<p class=\"language-cpp\">The example below shows a listing of all sender names created, adding a new one, setting it up as the default, and deleting it.<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>var senderFactory = new SenderFactory(client);\nvar senderNamesResp =    senderFactory.ActionList().Execute();\nforeach (var sender in senderNamesResp.List){\n      System.Console.WriteLine(\n            \"Name:\"\n            +sender.Name\n            +\", status: \"\n            +sender.Status\n            +\", dafault: \"\n            +sender.Default);\n}\nsenderFactory.ActionAdd(\"NewSenderName\").Execute();\nsenderFactory.ActionSetDefault(\"NewSenderName\").Execute();\nsenderFactory.ActionDelete(\"NewSenderName\").Execute();<\/code><\/pre>\n\n\n\n<p>In the following article on <strong>SMS branding<\/strong> (link below), you&#8217;ll find more tips and requirements concerning SMS sender names. I&#8217;ll just mention here that for security reasons, our employee must approve each request.&nbsp;There&#8217;s more to it, so read on!<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-smsapi-blog wp-block-embed-smsapi-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"IwovA1rTCg\"><a href=\"https:\/\/www.smsapi.com\/blog\/sender-id-how-to-send-branded-sms-company-name\/\">Sender ID \u2013 How to Send Branded SMS Messages with the Company Name Instead of a Number?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Sender ID \u2013 How to Send Branded SMS Messages with the Company Name Instead of a Number?&#8221; &#8212; SMSAPI Blog\" src=\"https:\/\/www.smsapi.com\/blog\/sender-id-how-to-send-branded-sms-company-name\/embed\/#?secret=RO4VFGc0mZ#?secret=IwovA1rTCg\" data-secret=\"IwovA1rTCg\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Scheduling SMS sending<\/h3>\n\n\n\n<p>An important matter when planning an SMS campaign is to put together a&nbsp;delivery schedule. When a notification reaches the client is essential for marketing effectiveness. SMS API enables you to <strong>set up the date and time of delivery<\/strong>.<\/p>\n\n\n\n<p class=\"language-cpp\">The&nbsp;<code>Action.SMSSend<\/code>&nbsp;class does this through the&nbsp;<code>SetDateSent(DateTime data)<\/code> method. An argument is a standard&nbsp;<code>System.DateTime<\/code> object. The following code will send an SMS on 14 November 2022 at 16:20:00 hours.<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>DateTime sendDate = new DateTime(2021, 9, 30,\n      16, 30, 0,\n      DateTimeKind.Local);\nvar sendResult = SMSFactory.ActionSend()\n      .SetTo(\"48111222333\")\n      .SetText(\"Hello in the future!\")\n      .SetDateSent(sendDate)\n      .Execute();<\/code><\/pre>\n\n\n\n<p class=\"language-cpp\">You can <strong>cancel a scheduled messaging<\/strong> using the&nbsp;<code>SMSDelete<\/code> action if you need to change your plans. You need a unique SMS ID from the system included in reply to its sending. Continuing with the previous code, it could look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>SMSFactory.ActionDelete(sendResult.List&#91;0].ID);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">More on scheduling SMS sending<\/h4>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-smsapi-blog wp-block-embed-smsapi-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"xQnq5aH4qJ\"><a href=\"https:\/\/www.smsapi.com\/blog\/how-to-schedule-sms-campaign\/\">How to Schedule an SMS Campaign Online?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to Schedule an SMS Campaign Online?&#8221; &#8212; SMSAPI Blog\" src=\"https:\/\/www.smsapi.com\/blog\/how-to-schedule-sms-campaign\/embed\/#?secret=oEfkVI3RMr#?secret=xQnq5aH4qJ\" data-secret=\"xQnq5aH4qJ\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Customising SMS contents<\/h3>\n\n\n\n<p>To make a good impression on the recipient, treat them like individuals. For example, you may address them by their first name. And no, it doesn&#8217;t mean you must manually type in every notification.<\/p>\n\n\n\n<p class=\"language-cpp\">Instead, you can&nbsp;<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/www.smsapi.com\/en\/personalization\">customise your message content<\/a>&nbsp;using dynamic parameters. The API enables using up to 4 parameters tagged within the text using special strings: [%1%], [%2%], [%3%] and [%4%]. Individual messages will be replaced with texts fed into the <code>SetParam(int i, string text)<\/code> method. This is shown in the example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>SMSFactory.ActionSend()\n      .SetTo(\"48111222333\", \"48444555666\")\n      .SetText(\"Hi &#91;%1%], your no. is &#91;%2%]!\")\n      .SetParam(0,&#91;\"Adam\", \"Bert\"])\n      .SetParam(1,&#91;\"11\", \"22\"])\n      .Execute();<\/code><\/pre>\n\n\n\n<p>The two messages will look as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"Hi Adam, your no. is 11!\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\"Hi Bert, your no. is 22!\"<\/code><\/pre>\n\n\n\n<p>With similarly constructed strings, you can use information from the contact database to send SMS using C#. This allows you to customise messages without putting parameter values in the code. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\"><code>SMSFactory.ActionSend()\n      .SetTo(\"48111222333\", \"48444555666\")\n      .SetText(\"Hello &#91;%name%], your number is &#91;%1%]!\")\n      .SetParam(0,&#91;\"11\", \"22\"])\n      .Execute();<\/code><\/pre>\n\n\n\n<p>The [%name%] field will be replaced with the relevant value assigned to the contact. You can find a list of standard fields in the&nbsp;<a href=\"https:\/\/www.smsapi.com\/docs\/#sms-messages-to-numbers-from-contacts-database-group\" target=\"_blank\" rel=\"noreferrer noopener\">bulk SMS sending documentation<\/a>.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Handling SMS sending errors \u2013 when not everything runs smoothly<\/h2>\n\n\n\n<p>You can easily guess that errors in the C# library are handled by throwing exceptions. The Library defines several types. They contain a&nbsp;message and an error code. Find the error code list with descriptions in their&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/docs\/#18-error-codes\" target=\"_blank\">Documentation section<\/a>. Expect the following exceptions in the Visual Studio console:<\/p>\n\n\n\n<ul class=\"language-cpp wp-block-list\">\n<li><code>ActionException<\/code>&nbsp;\u2013 different errors for individual actions. For example, code 11 means a message is too long or has no message content; 13 is an incorrect telephone number; 14 means an incorrect sender field; 26 is the message subject is too long.<\/li>\n\n\n\n<li><code>ClientExceptin<\/code>&nbsp;\u2013 HTTP client errors. The codes are, for example, 101 (incorrect token), 103 (insufficient points on account), and 105 (incorrect IP address).&nbsp;<\/li>\n\n\n\n<li><code>HostException<\/code>&nbsp;\u2013 server-side errors. Sample codes are 8 (call error) and 201 (internal system error).<\/li>\n\n\n\n<li><code>ProxyException<\/code>&nbsp;\u2013 these do not concern SMSAPI, but server connection, so they contain no codes. This exception is thrown in reaction to a Net.WebException.&nbsp;<\/li>\n\n\n\n<li><code>ArgumentException<\/code>&nbsp;\u2013 it&#8217;s an exception from the System space of the C# language. It&#8217;s thrown if you try to send an empty message or a recipient is a group and an individual number simultaneously (To and Group parameters rule each other out).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Other abilities of the C# SMS API library<\/h2>\n\n\n\n<p>As your business grows, you&#8217;ll probably expand the list of your projects to&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/en\/sms-notifications\" target=\"_blank\">SMS notifications<\/a>&nbsp;and marketing campaigns. If you happen to run into any problems, save yourself the trouble and chat with our support! You&#8217;ll find the link in the lower right corner of your screen.<\/p>\n\n\n\n<p class=\"language-cpp\">Manage them manually in the Customer Portal, or better, in the code using&nbsp;<a rel=\"noreferrer noopener nofollow\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/blob\/master\/smsapi\/Api\/ContactsFactory.cs\" target=\"_blank\"><code>ContactsFactory<\/code><\/a>. It provides many actions for listing, creating, editing and deleting contacts (and their individual fields) and whole groups. Take a look at the&nbsp;<a rel=\"noreferrer noopener nofollow\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/tree\/master\/smsapi\/Api\/Action\/Contacts\" target=\"_blank\">Action\/Contacts<\/a>&nbsp;and&nbsp;<a rel=\"noreferrer noopener nofollow\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/tree\/master\/smsapiTests\/Contacts\" target=\"_blank\">smsapiTests\/Contacts<\/a> folders in Visual Studio to learn about them in detail.<\/p>\n\n\n\n<p class=\"language-cpp\">In addition to SMS, you can also send MMS messages. The Library supports them with&nbsp;<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/blob\/master\/smsapi\/Api\/MMSFactory.cs\"><code>MMSFactory<\/code><\/a> in a manner very similar to how you handle SMS messages. As with SMS, you can set up the recipient(s) and sending time. The response is of the same&nbsp;<code>Response.Status<\/code> type as well. The content, of course, is not simple text but a message in the XML format SMIL, which you must first format correctly.<\/p>\n\n\n\n<p>I hope you now know how to use C# application to run SMS campaigns. If you&#8217;re uncertain how to use the particular methods, study the examples in the <a target=\"_blank\" rel=\"noreferrer noopener nofollow\" href=\"https:\/\/github.com\/smsapi\/smsapi-csharp-client\/tree\/master\/smsapiTests\">test catalogue<\/a>. You can also find explanations and program fragments in the&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/www.smsapi.com\/docs\/\">API documentation<\/a>. Good luck and successful texting using C#!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to send SMS messages from C#? Beginning with the basics, get to know our SMS API library, including sample code, practical advice, solutions to common problems, and more.<\/p>\n","protected":false},"author":21,"featured_media":5079,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[20,39],"class_list":["post-5065","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial","tag-english","tag-api"],"_links":{"self":[{"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/posts\/5065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/comments?post=5065"}],"version-history":[{"count":16,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/posts\/5065\/revisions"}],"predecessor-version":[{"id":5908,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/posts\/5065\/revisions\/5908"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/media\/5079"}],"wp:attachment":[{"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/media?parent=5065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/categories?post=5065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.smsapi.com\/blog\/wp-json\/wp\/v2\/tags?post=5065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}