Send SMS using Twillio in Asp.Net MVC | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

Send SMS using Twillio in Asp.Net MVC

Date- Oct 13,2022

3872

Free Download Pay & Download
Twillio Twillio In AspNet

Installing the Twilio NuGet package

NuGet\Install-Package Twilio.AspNet.Mvc -Version 6.0.0

After installing the Twilio package, we are going to modify the web config with the account SID and the auth token found from the Twilio dashboard

  <appSettings>
    <add key="config:AccountSid" value="AC3936d9aqq2323fedbdddd0ecd6df37199" /> <!--Replace with your AccountSid-->
    <add key="config:AuthToken" value="52b86f79c19bsassasasas704110dddddc26" />  <!--Replace with your AuthToken-->
    <add key="config:TwilioPhoneNum" value="+1845344098435" />  <!--Replace with your TwilioPhoneNum-->
  </appSettings>

The next part of our application is the API controller that will receive our requests. Let’s create the SmsController class within a Controllers folder:

using System;
using System.Configuration;
using System.Web.Mvc;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

namespace TwillioMVC.Controllers
{
    public class SmsController : Controller
    {
        // GET: Sms
        public ActionResult Index()
        {
            return View();
        }
         
        public ActionResult Create()
        {
            string accountSid = Convert.ToString(ConfigurationManager.AppSettings["config:AccountSid"]);
            string authToken = Convert.ToString(ConfigurationManager.AppSettings["config:AuthToken"]);
            string phone = Convert.ToString(ConfigurationManager.AppSettings["config:TwilioPhoneNum"]);
            TwilioClient.Init(accountSid, authToken);
            var message = MessageResource.Create(
            body: "Hello Code2night " + DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"),
            from: new Twilio.Types.PhoneNumber(phone),
            to: new Twilio.Types.PhoneNumber("+919034589555")
        );
            ViewData["Success"] = message.Sid;
            return View();
        }

    }
}


So, this is how we can integrate Twillio in Asp.net  and send sms using Twillio in Asp.net.

Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1190
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts