ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

how to send SMS with the sparrow SMS from aspnet core?

.Net .Net Core about 7 years ago || 12/14/2018 || 2.5 K View

  • Hide

Sparrow SMS is a Bulk SMS and SMS Marketing service to help businesses acquire and engage customers. A leading VAS provider in Nepal, Sparrow SMS was Initiated by Janaki Technology Pvt.

Let’s start

  • First, you need to create an account
  • They send the information about login details
  • Login with your account. They provide information your login details. Just like below.

  • We need to talk with them to verify our account. They provide us demo with 10 message. They will provide information on your register email.
  • Generate the tokensparrow message

After generating the token. So let dive into the code. Create a project on Aspnet Core from visual studio or vs code.

  1. Create from
@model SendInfo

<div>
    <form action="/home/send" method="post">
        <div class="form-group">
            <label asp-for="number"></label>
            <input asp-for="number" class="form-control" />
        </div>
        <div class="form-group">
            <label asp-for="message"></label>
            <input asp-for="message" class="form-control" />
        </div>
        <button type="submit" class="btn btn-primary" >Send</button>
    </form>
</div>

In Home controller create Method or function

using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ETransportation.Models;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using System.Text;

namespace ETransportation.Controllers
{
    public class HomeController : Controller
    {
        string api = "http://api.sparrowsms.com/";
        string token = "Random string";
        string from = "Demo";
        [HttpGet]
        public IActionResult Send()
        {
            return View();
        }
        [HttpPost]
        public async Task<IActionResult> Send(SendInfo sendInfo)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept
                    .Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response;

                var parameters = $"token={token}&from={from}" +
                    $"&to={sendInfo.number}&text={sendInfo.message}";

                response = await client.GetAsync(api+ "v2/sms/?"+ parameters);
                response.Content.ReadAsStringAsync().Result;
                if (response.IsSuccessStatusCode)
                {
                    sendInfo.message = “send succefully”;
                    return View(sendInfo);
                }
                else
                {
                     sendInfo.message = “send succefully”;

                    return View();
                }
            }
            
        }

In Success Response you will get this result.

"credit_consumedstring":1,
"response_codestring":200,
"countstring":1,
"credit_availablestring":7.0,
"responsestring":"1 mesages has been queued for deliverystring",
"message_idstring":194298012

For more details go here.

  • 1
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Anil Shrestha

Anil Shrestha

Qualified and skilled professional with experience working as a Software Developer

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey