{"id":17851,"date":"2026-11-18T23:39:44","date_gmt":"2026-11-18T18:09:44","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/"},"modified":"2026-11-19T00:46:12","modified_gmt":"2026-11-18T19:16:12","slug":"csharp-sms-api","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/","title":{"rendered":"Send SMS and OTP in C# \/ .NET with Fast2SMS API (HttpClient)"},"content":{"rendered":"<p>This guide shows how to send SMS and OTP from C# and .NET with the Fast2SMS API, using <code>HttpClient<\/code> and <code>System.Text.Json<\/code> that come with .NET. You will send a DLT SMS, send and verify a <a href=\"\/help\/smart-otp-setup-guide-fast2sms\/\">Smart OTP<\/a>, read delivery reports, receive webhooks in ASP.NET Core and handle errors. A complete client class is at the end for ASP.NET Core, a Windows service or a console app.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Send SMS from your .NET app<\/strong><p>Copy your API key, add your DLT or Smart OTP template and send your first message from C#.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Before you start<\/h2>\n<ul>\n<li><strong>.NET 6 or later<\/strong> (the examples use top-level statements and minimal APIs). No NuGet package is needed.<\/li>\n<li><strong>API key<\/strong> from <strong>API Key<\/strong> under UTILITY, with <strong>API Access<\/strong> on.<\/li>\n<li><strong>DLT SMS:<\/strong> an approved sender ID and template in <strong>DLT Manager<\/strong>, and the template&#8217;s <strong>Message ID<\/strong>.<\/li>\n<li><strong>OTP:<\/strong> a Smart OTP template and its <strong>OTP ID<\/strong>.<\/li>\n<li><strong>Wallet balance<\/strong> for SMS, OTP sends and resends, which are all charged.<\/li>\n<li><strong>Server side only.<\/strong> Do not put the key in a WinForms, WPF, MAUI or Blazor WebAssembly app that you give to users. They can read it.<\/li>\n<\/ul>\n<h2>Get the key and IDs from the panel<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>API key<\/h3>\n<p>Go to <strong>Account Setting<\/strong>, <strong>API Key<\/strong>, click <strong>View<\/strong>, enter the OTP sent to your account mobile and copy the <strong>Authorization Key<\/strong>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with a masked Authorization Key, View and Reset buttons and the API Access switch on\"><figcaption>Keep it in user secrets, environment variables or a vault.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Message ID and sender ID<\/h3>\n<p>Open <strong>DLT Manager<\/strong>, <strong>Content Template<\/strong>, and copy the <strong>Message ID<\/strong> and <strong>Sender ID<\/strong> from an approved template card.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/sms-dlt-template-list-hd-1-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Approved content template cards in DLT Manager with Message ID, Sender ID, masked Template ID and Entity\"><figcaption>The Message ID is not the 19-digit Template ID.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>OTP ID<\/h3>\n<p>Open Smart OTP, <strong>OTP Template List<\/strong>, and copy the <strong>OTP ID<\/strong> of the template you will use.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-3-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Smart OTP Template List cards with OTP ID, name or sender, template ID and fallback rows\"><figcaption>Each OTP template has its own OTP ID.<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<h2>Set up the project<\/h2>\n<pre><code class=\"language-bash\">dotnet new console -n SmsDemo\ncd SmsDemo\n# keep the key out of source control\nsetx FAST2SMS_API_KEY \"YOUR_API_KEY\"          # Windows (open a new terminal after this)\nexport FAST2SMS_API_KEY=\"YOUR_API_KEY\"        # Linux \/ macOS<\/code><\/pre>\n<p>In ASP.NET Core you can also use <code>dotnet user-secrets set \"Fast2SMS:ApiKey\" \"YOUR_API_KEY\"<\/code> for development and an environment variable in production.<\/p>\n<p>One shared <code>HttpClient<\/code> and a helper:<\/p>\n<pre><code class=\"language-csharp\">using System.Net.Http.Json;\nusing System.Text.Json;\n\nvar http = new HttpClient { BaseAddress = new Uri(\"https:\/\/www.fast2sms.com\"), Timeout = TimeSpan.FromSeconds(15) };\nhttp.DefaultRequestHeaders.TryAddWithoutValidation(\"authorization\", Environment.GetEnvironmentVariable(\"FAST2SMS_API_KEY\"));\n\nasync Task&lt;(bool ok, JsonElement json)&gt; PostAsync(string path, object body)\n{\n    var res = await http.PostAsJsonAsync(path, body);\n    var json = await res.Content.ReadFromJsonAsync&lt;JsonElement&gt;();\n    var ok = res.IsSuccessStatusCode\n             &amp;&amp; json.TryGetProperty(\"return\", out var r) &amp;&amp; r.ValueKind == JsonValueKind.True;\n    return (ok, json);\n}<\/code><\/pre>\n<div class=\"f2s-note\">Use <code>TryAddWithoutValidation(\"authorization\", key)<\/code> with the bare key. Do not use <code>AuthenticationHeaderValue(\"Bearer\", key)<\/code>. The OTP endpoints do not strip &#8220;Bearer &#8221; and reply &#8220;Invalid authorization key&#8221;.<\/div>\n<h2>Send a DLT SMS in C#<\/h2>\n<p>Post to <code>\/dev\/bulkV2<\/code> with <code>route = \"dlt\"<\/code>. The example template is Message ID 10001 on DEMOTR with four variables (name, order, amount, date).<\/p>\n<pre><code class=\"language-csharp\">var (ok, json) = await PostAsync(\"\/dev\/bulkV2\", new Dictionary&lt;string, string&gt;\n{\n    [\"route\"] = \"dlt\",\n    [\"sender_id\"] = \"DEMOTR\",                                   \/\/ exact case\n    [\"message\"] = \"10001\",                                      \/\/ Message ID\n    [\"variables_values\"] = string.Join(\"|\", \"Rahul\", \"DT10458\", \"1240\", \"21 Nov\"),\n    [\"numbers\"] = string.Join(\",\", \"9999999999\", \"8888888888\"),\n    [\"udf1\"] = \"order-DT10458\",                                 \/\/ optional\n});\n\nif (ok)\n    Console.WriteLine($\"Queued: {json.GetProperty(\"request_id\").GetString()}\");   \/\/ S...\nelse\n    Console.WriteLine($\"Not sent: {json}\");<\/code><\/pre>\n<ul>\n<li>Values follow the order of <code>{#var#}<\/code> in the template. Each is cut to 40 characters.<\/li>\n<li>The sender ID is case-sensitive.<\/li>\n<li>The success reply&#8217;s <code>message<\/code> is an array, <code>[\"SMS sent successfully.\"]<\/code>. Queued, not yet delivered.<\/li>\n<li>Send later with <code>[\"schedule_time\"] = \"25-11-2026-10-30\"<\/code> (DD-MM-YYYY-HH-MM, IST).<\/li>\n<\/ul>\n<h2>Send and verify a Smart OTP<\/h2>\n<pre><code class=\"language-csharp\">\/\/ Send\nvar (sent, sendJson) = await PostAsync(\"\/dev\/otp\/send\", new\n{\n    mobile = \"9999999999\",\n    otp_id = \"YOUR_OTP_ID\",\n    otp_expiry = 5,     \/\/ minutes, 1 to 10080, default 15\n    otp_length = 6      \/\/ 4 to 10, default 6\n});\nConsole.WriteLine(sent ? \"OTP sent\" : sendJson.GetProperty(\"message\").ToString());\n\n\/\/ Verify the code the user typed\nvar (verified, verifyJson) = await PostAsync(\"\/dev\/otp\/verify\", new { mobile = \"9999999999\", otp = \"482913\" });\nConsole.WriteLine(verified ? \"Verified\" : verifyJson.GetProperty(\"message\").ToString());\n\n\/\/ Resend the same OTP (charged again)\nvar (resent, resendJson) = await PostAsync(\"\/dev\/otp\/resend\", new { mobile = \"9999999999\" });<\/code><\/pre>\n<ul>\n<li>Verify takes only the mobile and the code, and checks the latest unverified OTP for that number.<\/li>\n<li>Each new send to a number cancels its older OTPs.<\/li>\n<li>Resend sends the same code again. It works within 10 minutes of the first send, with at most 5 sends in all (the first counts).<\/li>\n<li>Calls inside the wait time get &#8220;Please wait N seconds before requesting a new OTP&#8221;. Change the wait in <strong>OTP Settings<\/strong> (default 10 seconds).<\/li>\n<\/ul>\n<h2>Delivery reports<\/h2>\n<p>Use the DLR API or a webhook, not both for the same messages. Reading the DLR by API can stop the webhook for those rows.<\/p>\n<h3>DLR API<\/h3>\n<pre><code class=\"language-csharp\">var dlr = await http.GetFromJsonAsync&lt;JsonElement&gt;(\"\/dev\/dlr\/Sa1B2c3D4e5F6g7\");\nif (dlr.TryGetProperty(\"success\", out var s) &amp;&amp; s.GetBoolean())\n{\n    foreach (var row in dlr.GetProperty(\"data\")[0].GetProperty(\"delivery_status\").EnumerateArray())\n        Console.WriteLine($\"{row.GetProperty(\"mobile\")} {row.GetProperty(\"status\").GetString()}\");\n}<\/code><\/pre>\n<p><code>GetFromJsonAsync<\/code> throws on a <a href=\"\/help\/error-otp-not-found-or-already-verified\/\">404<\/a> (&#8220;No DLR found&#8230;&#8221;), so wrap it in <code>try<\/code>\/<code>catch (HttpRequestException)<\/code>. Status is Delivered, Failed or Sent (report pending). It looks back 7 days.<\/p>\n<h3>ASP.NET Core webhook receiver<\/h3>\n<p>In the panel, open <strong>Webhook<\/strong>, <strong>SMS<\/strong> or <strong>OTP<\/strong>, and add a webhook: format <strong>Standard Webhook<\/strong>, method POST, content type JSON, your public URL. Each call appears in <strong>Webhook Logs<\/strong>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/webhook-logs-hd-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Webhook Logs with SMS and WhatsApp entries showing method, event such as DELIVERED or FAILED, URL, time, HTTP code and Success or Failed\"><figcaption>A 404 or 5xx from your server shows here as Failed.<\/figcaption><\/figure>\n<pre><code class=\"language-csharp\">var builder = WebApplication.CreateBuilder(args);\nvar app = builder.Build();\n\napp.MapPost(\"\/fast2sms\/webhook\", (HttpRequest req, Dictionary&lt;string, object?&gt; body) =&gt;\n{\n    \/\/ Optional: a header you added in the webhook's Headers tab\n    if (req.Headers[\"X-Webhook-Token\"] &#33;= Environment.GetEnvironmentVariable(\"MY_WEBHOOK_TOKEN\"))\n        return Results.Unauthorized();\n\n    var requestId = body.GetValueOrDefault(\"request_id\")?.ToString();\n    var mobile    = body.GetValueOrDefault(\"mobile\")?.ToString();\n    var status    = body.GetValueOrDefault(\"status\")?.ToString();   \/\/ delivered or failed\n    \/\/ save the status, then return quickly\n    return Results.Ok(\"OK\");\n});\n\napp.Run();<\/code><\/pre>\n<p>Return 2xx within 10 seconds. On a timeout, 408, 429 or 5xx, Fast2SMS tries again up to 3 times, 60 seconds apart. Webhooks are sent only for API messages whose report arrives within 24 hours.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Delivery status straight into your .NET app<\/strong><p>Add a webhook once and receive delivered or failed status for every SMS and OTP sent by API.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Error handling<\/h2>\n<ul>\n<li><strong>Check the <code>return<\/code> field.<\/strong> Low balance can come back as HTTP 200 with <code>\"return\": false<\/code> (status_code 416), so <code>IsSuccessStatusCode<\/code> alone is not enough.<\/li>\n<li><strong>Do not add Polly retries to send calls.<\/strong> A <code>TaskCanceledException<\/code> (timeout) does not prove the SMS failed. A retry can send and charge twice. Retry once only when the connection could not be made. Verify can be retried once.<\/li>\n<li><strong>Reuse one HttpClient<\/strong> (or <code>IHttpClientFactory<\/code>) instead of creating one per message.<\/li>\n<li><strong>Use API Logs<\/strong> in the panel to see each request and response from the last 7 days.<\/li>\n<\/ul>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Reply<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>412 Invalid Authentication, Check Authorization Key (HTTP 401)<\/td>\n<td>Key wrong, reset, or the environment variable is empty.<\/td>\n<\/tr>\n<tr>\n<td>Invalid authorization key (OTP, HTTP 401)<\/td>\n<td>Remove the &#8220;Bearer &#8221; prefix.<\/td>\n<\/tr>\n<tr>\n<td>413 Authorization Key Disabled<\/td>\n<td>Turn <strong>API Access<\/strong> on.<\/td>\n<\/tr>\n<tr>\n<td>414 IP is blacklisted from Dev API section<\/td>\n<td>Whitelist the server IP in <strong>API Security<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>406 Invalid Sender ID<\/td>\n<td>Use the approved sender, same case.<\/td>\n<\/tr>\n<tr>\n<td>424 Invalid Message ID<\/td>\n<td>Use the Message ID linked to that sender.<\/td>\n<\/tr>\n<tr>\n<td>411 Invalid Numbers<\/td>\n<td>No valid 10-digit Indian mobile in the list.<\/td>\n<\/tr>\n<tr>\n<td>416 You don&#8217;t have sufficient wallet balance<\/td>\n<td>Recharge.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP ID<\/td>\n<td>Copy the OTP ID again; check the account.<\/td>\n<\/tr>\n<tr>\n<td>Please wait N seconds before requesting a new OTP<\/td>\n<td>Wait and show a timer.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP \/ OTP expired \/ Maximum verification attempts reached<\/td>\n<td>Let the user retry, or send a new OTP.<\/td>\n<\/tr>\n<tr>\n<td>OTP not found or already verified (HTTP 404)<\/td>\n<td>Send a new OTP.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Full copy-paste example: Fast2SmsClient.cs<\/h2>\n<pre><code class=\"language-csharp\">using System.Net.Http.Json;\nusing System.Text.Json;\n\npublic sealed record Fast2SmsResult(bool Ok, int Http, string? StatusCode, string? RequestId, string Message, JsonElement? Raw);\n\npublic sealed class Fast2SmsClient\n{\n    private readonly HttpClient _http;\n\n    public Fast2SmsClient(HttpClient http, string apiKey)\n    {\n        _http = http;\n        _http.BaseAddress ??= new Uri(\"https:\/\/www.fast2sms.com\");\n        _http.Timeout = TimeSpan.FromSeconds(15);\n        _http.DefaultRequestHeaders.Remove(\"authorization\");\n        _http.DefaultRequestHeaders.TryAddWithoutValidation(\"authorization\", apiKey);\n    }\n\n    public Task&lt;Fast2SmsResult&gt; SendDltAsync(string senderId, string messageId, IEnumerable&lt;string&gt; vars, IEnumerable&lt;string&gt; numbers) =&gt;\n        CallAsync(HttpMethod.Post, \"\/dev\/bulkV2\", new Dictionary&lt;string, string&gt;\n        {\n            [\"route\"] = \"dlt\",\n            [\"sender_id\"] = senderId,\n            [\"message\"] = messageId,\n            [\"variables_values\"] = string.Join(\"|\", vars),\n            [\"numbers\"] = string.Join(\",\", numbers),\n        });\n\n    public Task&lt;Fast2SmsResult&gt; SendOtpAsync(string mobile, string otpId, int expiryMinutes = 5) =&gt;\n        CallAsync(HttpMethod.Post, \"\/dev\/otp\/send\", new { mobile, otp_id = otpId, otp_expiry = expiryMinutes });\n\n    public Task&lt;Fast2SmsResult&gt; VerifyOtpAsync(string mobile, string otp) =&gt;\n        CallAsync(HttpMethod.Post, \"\/dev\/otp\/verify\", new { mobile, otp });\n\n    public Task&lt;Fast2SmsResult&gt; ResendOtpAsync(string mobile) =&gt;\n        CallAsync(HttpMethod.Post, \"\/dev\/otp\/resend\", new { mobile });\n\n    public Task&lt;Fast2SmsResult&gt; DeliveryReportAsync(string requestId) =&gt;\n        CallAsync(HttpMethod.Get, \"\/dev\/dlr\/\" + Uri.EscapeDataString(requestId), null);\n\n    private async Task&lt;Fast2SmsResult&gt; CallAsync(HttpMethod method, string path, object? body)\n    {\n        HttpResponseMessage res;\n        try\n        {\n            var req = new HttpRequestMessage(method, path);\n            if (body &#33;= null) req.Content = JsonContent.Create(body);\n            res = await _http.SendAsync(req);\n        }\n        catch (HttpRequestException ex)\n        {\n            return new Fast2SmsResult(false, 0, null, null, \"Network error: \" + ex.Message, null);\n        }\n        catch (TaskCanceledException)\n        {\n            \/\/ Timed out: the message may still go out. Do not resend automatically.\n            return new Fast2SmsResult(false, 0, null, null, \"Timeout, check API Logs before resending\", null);\n        }\n\n        JsonElement json;\n        try { json = await res.Content.ReadFromJsonAsync&lt;JsonElement&gt;(); }\n        catch (JsonException) { return new Fast2SmsResult(false, (int)res.StatusCode, null, null, \"Non-JSON response\", null); }\n\n        bool Flag(string name) =&gt; json.TryGetProperty(name, out var v) &amp;&amp; v.ValueKind == JsonValueKind.True;\n        string? Str(string name) =&gt; json.TryGetProperty(name, out var v) ? v.ToString() : null;\n\n        var message = json.TryGetProperty(\"message\", out var m)\n            ? (m.ValueKind == JsonValueKind.Array ? string.Join(\" \", m.EnumerateArray().Select(x =&gt; x.GetString())) : m.ToString())\n            : \"\";\n\n        var ok = res.IsSuccessStatusCode &amp;&amp; (Flag(\"return\") || Flag(\"success\"));\n        return new Fast2SmsResult(ok, (int)res.StatusCode, Str(\"status_code\"), Str(\"request_id\"), message, json);\n    }\n}\n\n\/\/ Usage (console app, top-level statements):\n\/\/ var f2s = new Fast2SmsClient(new HttpClient(), Environment.GetEnvironmentVariable(\"FAST2SMS_API_KEY\")&#33;);\n\/\/ var sms = await f2s.SendDltAsync(\"DEMOTR\", \"10001\", new[] { \"Rahul\", \"DT10458\", \"1240\", \"21 Nov\" }, new[] { \"9999999999\" });\n\/\/ Console.WriteLine(sms.Ok ? $\"SMS queued: {sms.RequestId}\" : $\"SMS error: {sms.Message}\");\n\/\/ var otp = await f2s.SendOtpAsync(\"9999999999\", \"YOUR_OTP_ID\");\n\/\/ var check = await f2s.VerifyOtpAsync(\"9999999999\", \"482913\");\n\/\/ Console.WriteLine(check.Ok ? \"Verified\" : check.Message);<\/code><\/pre>\n<p>In ASP.NET Core, register it with <code>builder.Services.AddHttpClient&lt;Fast2SmsClient&gt;()<\/code> and pass the key from configuration in a factory. The DLR API replies with <code>success<\/code> instead of <code>return<\/code>, so the client checks both. Fast2SMS also has an ASP.NET Core starter kit with this client, OTP endpoints, a mock server and tests.<\/p>\n<h2>Common problems and fixes<\/h2>\n<ul>\n<li><strong>&#8220;The format of value &#8230; is invalid&#8221; when adding the header:<\/strong> use <code>TryAddWithoutValidation<\/code>, not <code>Add<\/code>.<\/li>\n<li><strong>Key works locally but not on IIS:<\/strong> the app pool does not see your user&#8217;s environment variable. Set it in the app pool, <code>web.config<\/code> environment variables or your hosting panel.<\/li>\n<li><strong>Error 414 on Azure or a VPS:<\/strong> whitelist the outbound IP in <strong>API Security<\/strong>, or turn API Security off.<\/li>\n<li><strong>Socket exhaustion under load:<\/strong> you are creating a new <code>HttpClient<\/code> per call. Reuse one, or use <code>IHttpClientFactory<\/code>.<\/li>\n<li><strong>Hindi text looks wrong:<\/strong> <code>JsonContent<\/code> sends UTF-8. Check that your database columns store Unicode (<code>nvarchar<\/code>).<\/li>\n<\/ul>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Is there a Fast2SMS NuGet package?<\/h3>\n<p>You do not need one. The API is HTTPS with JSON, and the class above uses only .NET&#8217;s own libraries.<\/p>\n<h3>Does this work with .NET Framework 4.x?<\/h3>\n<p>The API works with any HTTP client. On .NET Framework, use <code>HttpClient<\/code> with <code>StringContent<\/code> and Newtonsoft.Json, and make sure TLS 1.2 is enabled.<\/p>\n<h3>Can a desktop app call the API directly?<\/h3>\n<p>Only if the key stays on machines you control. For apps you give to customers, put the key on your server and let the app call your server.<\/p>\n<h3>How do I send the same SMS to many numbers?<\/h3>\n<p>Put them comma-separated in <code>numbers<\/code>. Invalid numbers are skipped and not charged.<\/p>\n<h3>Is OTP verify charged?<\/h3>\n<p>No. Send and resend are charged; verify is free.<\/p>\n<h3>Can I set my own OTP?<\/h3>\n<p>Yes. Add <code>otp<\/code> (up to 10 characters) to the send call. Fast2SMS still verifies it for you.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Add SMS and OTP to your .NET app<\/strong><p>Sign up, set up your DLT or Smart OTP template and drop the client above into ASP.NET Core.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"\/help\/dlt-sms-api-guide\/\">Fast2SMS DLT SMS API: send SMS with your DLT template<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-send-otp-api\/\">Fast2SMS Send OTP API: parameters and code examples<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-verify-otp-api\/\">Fast2SMS Verify OTP API: how verification works<\/a><\/li>\n<li><a href=\"\/help\/fast2sms-webhooks-setup-delivery-reports\/\">Webhooks in Fast2SMS: get delivery reports on your own URL<\/a><\/li>\n<li><a href=\"\/help\/api-security-ip-whitelist\/\">Restrict the Fast2SMS API to your server IP<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/bulk-sms\">Fast2SMS Bulk SMS<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows how to send SMS and OTP from C# and .NET with the Fast2SMS API, using HttpClient and System.Text.Json that come with .NET. You will send a DLT SMS, send and verify a Smart OTP, read delivery reports, receive webhooks in ASP.NET Core and handle errors. A complete client class is at the [&hellip;]<\/p>\n","protected":false},"featured_media":17845,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,13,5],"tags":[],"class_list":["post-17851","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-bulk-sms","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Send SMS and OTP in C# .NET: SMS API Code | Fast2SMS<\/title>\n<meta name=\"description\" content=\"Send DLT SMS and OTP from C# and .NET with the Fast2SMS API and HttpClient. Smart OTP verify, delivery report, ASP.NET Core webhook and a ready client.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send SMS and OTP in C# .NET: SMS API Code | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"Send DLT SMS and OTP from C# and .NET with the Fast2SMS API and HttpClient. Smart OTP verify, delivery report, ASP.NET Core webhook and a ready client.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Fast2SMS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Fast2SMS\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T18:09:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T19:16:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fast2sms\" \/>\n<meta name=\"twitter:site\" content=\"@fast2sms\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"Send SMS and OTP in C# \\\/ .NET with Fast2SMS API (HttpClient)\",\"datePublished\":\"2026-11-18T18:09:44+00:00\",\"dateModified\":\"2026-11-18T19:16:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/\"},\"wordCount\":1244,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-2-scaled.webp\",\"articleSection\":[\"API\",\"Bulk SMS\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/\",\"name\":\"Send SMS and OTP in C# .NET: SMS API Code | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-2-scaled.webp\",\"datePublished\":\"2026-11-18T18:09:44+00:00\",\"dateModified\":\"2026-11-18T19:16:12+00:00\",\"description\":\"Send DLT SMS and OTP from C# and .NET with the Fast2SMS API and HttpClient. Smart OTP verify, delivery report, ASP.NET Core webhook and a ready client.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-2-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-2-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"API Key page with a masked Authorization Key, View and Reset buttons and the API Access switch on\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/csharp-sms-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/api\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Send SMS and OTP in C# \\\/ .NET with Fast2SMS API (HttpClient)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\",\"name\":\"Fast2SMS\",\"description\":\"Help\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"inLanguage\":\"en-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\",\"name\":\"Fast2SMS\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"caption\":\"Fast2SMS\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\"},\"email\":\"support@fast2sms.com\",\"telephone\":\"+91-6262778822\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Fast2SMS\",\"https:\\\/\\\/www.instagram.com\\\/fast2sms\",\"https:\\\/\\\/x.com\\\/fast2sms\",\"https:\\\/\\\/www.youtube.com\\\/Fast2SMSofficial\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/fast2sms\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send SMS and OTP in C# .NET: SMS API Code | Fast2SMS","description":"Send DLT SMS and OTP from C# and .NET with the Fast2SMS API and HttpClient. Smart OTP verify, delivery report, ASP.NET Core webhook and a ready client.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/","og_locale":"en_US","og_type":"article","og_title":"Send SMS and OTP in C# .NET: SMS API Code | Fast2SMS","og_description":"Send DLT SMS and OTP from C# and .NET with the Fast2SMS API and HttpClient. Smart OTP verify, delivery report, ASP.NET Core webhook and a ready client.","og_url":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T18:09:44+00:00","article_modified_time":"2026-11-18T19:16:12+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_creator":"@fast2sms","twitter_site":"@fast2sms","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"Send SMS and OTP in C# \/ .NET with Fast2SMS API (HttpClient)","datePublished":"2026-11-18T18:09:44+00:00","dateModified":"2026-11-18T19:16:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/"},"wordCount":1244,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp","articleSection":["API","Bulk SMS","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/","url":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/","name":"Send SMS and OTP in C# .NET: SMS API Code | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp","datePublished":"2026-11-18T18:09:44+00:00","dateModified":"2026-11-18T19:16:12+00:00","description":"Send DLT SMS and OTP from C# and .NET with the Fast2SMS API and HttpClient. Smart OTP verify, delivery report, ASP.NET Core webhook and a ready client.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-2-scaled.webp","width":2560,"height":1600,"caption":"API Key page with a masked Authorization Key, View and Reset buttons and the API Access switch on"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/csharp-sms-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fast2sms.com\/help\/"},{"@type":"ListItem","position":2,"name":"API","item":"https:\/\/www.fast2sms.com\/help\/api\/"},{"@type":"ListItem","position":3,"name":"Send SMS and OTP in C# \/ .NET with Fast2SMS API (HttpClient)"}]},{"@type":"WebSite","@id":"https:\/\/www.fast2sms.com\/help\/#website","url":"https:\/\/www.fast2sms.com\/help\/","name":"Fast2SMS","description":"Help","publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"inLanguage":"en-IN"},{"@type":"Organization","@id":"https:\/\/www.fast2sms.com\/#organization","name":"Fast2SMS","url":"https:\/\/www.fast2sms.com\/","logo":{"@type":"ImageObject","@id":"https:\/\/www.fast2sms.com\/#logo","url":"https:\/\/www.fast2sms.com\/Fast2SMS.png","contentUrl":"https:\/\/www.fast2sms.com\/Fast2SMS.png","caption":"Fast2SMS"},"image":{"@id":"https:\/\/www.fast2sms.com\/#logo"},"email":"support@fast2sms.com","telephone":"+91-6262778822","sameAs":["https:\/\/www.facebook.com\/Fast2SMS","https:\/\/www.instagram.com\/fast2sms","https:\/\/x.com\/fast2sms","https:\/\/www.youtube.com\/Fast2SMSofficial","https:\/\/www.linkedin.com\/company\/fast2sms"]}]}},"_links":{"self":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/17851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/comments?post=17851"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/17851\/revisions"}],"predecessor-version":[{"id":19271,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/17851\/revisions\/19271"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/17845"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=17851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=17851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=17851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}