SMS and MMS Marketing Notifications with C# and ASP.NET MVC

SMS および MMS マーケティング通知を実装する準備はできましたか?

Excellent - you've come to the right place. Today we'll explore adding them to a C# and ASP.NET MVC application.


  1. A possible customer sends an SMS to a Twilio phone number you advertise somewhere.
  2. Your application confirms that the user wants to receive SMS and MMS notifications from your company.
  3. 管理者またはマーケティングキャンペーンマネージャーは、ウェブフォームを使用して、すべての購読者に SMS/MMS メッセージで送信されるメッセージを作成します。


To get this done, we'll be working with the following Twilio tools:

さぁ、はじめましょう! 矢印ボタンをクリックして、チュートリアルの次のステップに進みましょう。


In order to send out marketing notifications to a subscriber, we need to first provide the right model:

  • PhoneNumber will store where to send the notifications.
  • Subscribed will store who is opted in to receive notifications.



        Next, let's look at how we'll manage incoming messages.



        It relies on a MessageCreator abstraction that produces the message that will be returned to the sender. It also neatly hides the complexity behind creating new subscribers.

        Twilio can send your web application an HTTP request when certain events happen, such as an incoming text message to one of your Twilio phone numbers. These requests are called webhooks, or status callbacks. For more, check out our guide to Getting Started with Twilio Webhooks. Find other webhook pages, such as a security guide and an FAQ in the Webhooks section of the docs.


              The Subscribers Controller


              When a new user sends us a message, we need to manage adding him or her to our database. We'll explore that functionality next.

              Add Some New Users

              Creating New Subscribers

              We begin by getting a new customer's phone number from the incoming Twilio request. Next, we try to find a Subscriber model with that phone number.

              If there's no subscriber with this phone number, we create one, save it, and respond with a friendly message asking to reply "add" back. We are very careful to confirm they want to receive messages from our company before flagging them as subscribed.


                    Looking up a user and potentially adding them to the database


                    このステップですべきことはこれでおしまいです。 メッセージを要求した人を捕捉するため、Subscriber オブジェクトを作成しました。 また彼らが初回にメッセージを送信するときに、それをデータベースに保存します。

                    Next let's go further and look at how a user will modify his or her subscriber status.


                    ユーザーの購読状態の管理に、addremove という2つのSMSコマンドを提供することにします。 

                    These commands will toggle a boolean flag for their Subscriber record in the database, and will determine whether or not they want to receive messages from our marketing campaign. Because we want to respect our users' desires, we don't opt them in automatically. We are sure to have them confirm that they want to receive our messages.


                    • ユーザーがすでにデータベースに登録されている場合、送られてきたメッセージを解析して既知のコマンドであるかどうか確認します。
                    • If it is a add or remove command, update her or his subscription status in the database.
                    • If it is a command we don't recognize, send her or him a message explaining available commands.

                          Dealing with incoming user commands


                          With the logic behind subscribing and unsubscribing implemented, let's move on to sending messages out.


                          On the server, we grab an incoming form's text and (optional) image URL, then loop through all Subscribers to call the method Send on our MessageSender domain object.

                          When the messages are on their way, we redirect the form submitter back to the same form with a ViewBag Property message containing feedback about the messaging attempt.


                                The Notifications controller


                                And how do we actually send the MMS or SMS messages? Glad you asked - let's go there next.

                                Send MMS and SMS Messages

                                SMS または MMS 通知を送信する

                                Now that we have a list of subscribers for our awesome SMS and MMS content, we need to provide our marketing team some kind of interface to send out their perfectly crafted messages.

                                When the model object is loaded, it initializes a Twilio REST API client that it can be used to send SMS and MMS messages. The client requires your Twilio account credentials (an account SID and auth token), which can be found in the console:


                                Next all we need to do is call MessageResource.CreateAsync in order to send our message. The Twilio Message API call requires a From and To parameter, and either Body or a MediaUrl (or both).


                                      A Notifications service


                                      And that's a wrap! You should now be able to easily integrate this awesome feature into your own application. On the next pane, we'll look at some other easy-to-implement features.



                                      That's it! We've just implemented a an opt-in process and an administrative interface to run an SMS and MMS marketing campaign all through C# and ASP.NET MVC. Now all you need is killer content to share with your users via text or MMS... and you're on your own for that.

                                      Twilio and .NET go together very well - perhaps you'd enjoy these other tutorials?

                                      IVR: フォンツリー

                                      Build an automated phone tree with C# and Twilio's powerful features.


                                      Don't let valuable feedback slip away - conduct instant surveys with voice or SMS.



                                      We'd love to hear from you - Tweet to us @twilio with what you're building!

                                      Hector Ortega Kat King Mica Swyers Andrew Baker Paul Kamp


                                      誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。



                                            We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

                                            Sending your feedback...
                                            🎉 Thank you for your feedback!
                                            Something went wrong. Please try again.

                                            Thanks for your feedback!

                                            Refer us and get $10 in 3 simple steps!


                                            Get link

                                            Get a free personal referral link here


                                            Give $10

                                            Your user signs up and upgrade using link


                                            Get $10

                                            1,250 free SMSes
                                            OR 1,000 free voice mins
                                            OR 12,000 chats
                                            OR more