Send SMS using Twillio in Asp.Net MVC | Code2night.com
Code2night
  • Home
  • Blogs
  • Tutorial
  • Post Blog
  • Members
    • Register
    • Login
  1. Home
  2. Blogpost
13 Oct
2022

Send SMS using Twillio in Asp.Net MVC

1154

Subscribe Youtube & Download free Pay & Download

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.

  • |
  • Twilio SMS And ASPNET MVC , How To Send An SMS With ASPNET MVC , Twillio , Twillio In AspNet , Twillio SMS Integration

Comments

Follow Us On Social Media - Like Us On Facebook

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 New Subscribers!

Subscribe and Click on Verify and Download for download link

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

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading

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 © 2023 by Code2night. All Rights Reserved

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