メニュー

Expand
Rate this page:

Thanks for rating this page!

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

Send SMS Messages with a Messaging Service in Java

Using a Twilio Messaging Service improves your customers' SMS message experience with routing and content intelligence features that you can control from the Twilio console. A Messaging Service is a higher-level “bundling” of messaging functionality around a common set of senders, features, and configuration.

This guide will help you understand what a Messaging Service can do for you and show you how to send SMS messages with a Service in your Java application. The code snippets in this guide are written using the Java SDK version 7 or higher, and make use of the Twilio Java SDK.

はじめましょう!

Why use a Messaging Service?

Sending messages at a high volume and/or at a global scale quickly balloons in complexity. That's why Twilio Programmable Messaging encourages the use of Messaging Services to manage your senders, maintain compliance with local carrier regulations, and create a smooth and consistent messaging experience for your end users.

Some Messaging Service features include:

  • Sticky Sender: Use the same From phone number to message a given customer for a consistent experience
  • Smart Encoding: Save space (and money!) by automatically converting hard-to-catch Unicode characters to UCS-2 compliant characters
  • MMS Converter: Automatically convert links to media files for areas in which MMS is not supported
  • Advanced Opt-Out: Manage your opt-out, opt-in, and help keywords and messages
  • Sender ID pre-registration alert: Get notifications when you are sending messages in countries that require pre-registration of your Alphanumeric Sender ID
  • ...and more!

For more information, check out the list of Messaging Service Features with descriptions and configuration information for each feature.

Create and Configure a Messaging Service

You can create a Messaging Service through the Twilio Console or using the REST API with the following code:

        
        
        
        

        SMS機能の利用できる電話番号を購入する

        Sending SMS messages requires an SMS capable phone number. You can search for and purchase available phone numbers in the Console. When you search, make sure that the number you choose is SMS capable. Check the appropriate box in the search UI to filter available numbers to those that are SMS capable.

        SMSの利用できる番号を検索する

        検索結果の表示時に、どの番号でSMSが利用できるか確認できます。

        SMSの利用できる番号を購入しましょう。

        ピッカピカの新しいTwilio電話番号で、モバイル機器にSMSを送りはじめることができます。

        Add a number to the Messaging Service's sender pool

        Now, associate your Twilio number with the Messaging Service that you created.

        You can do this in the Twilio Console in the Senders section under your Messaging Service. Click the Add Sender IDs button, select the Sender Type, and assign the senders to your Messaging Service.

        You can also use the Messaging Services REST API to add the Phone Number you purchased to your sender pool. To do this, you will need the Phone Number's unique SID, which starts with PNXXX. You can find this in the Phone Numbers Section of the Twilio Console.

        find_phone_number_sid.png

        Use the Phone Number's SID to attach to the Messaging Service that you created:

              
              
              
              
              Add your new phone number to the Sender Pool for your Messaging Service

              Add a phone number to the Sender Pool

              Add your new phone number to the Sender Pool for your Messaging Service

              You must add at least one phone number to the Sender pool for your Messaging Service before it can send messages.

              Send an SMS Message with a Messaging Service

              Sending a message with a Messaging Service is a lot like sending a message from a Twilio number, with one key difference. Instead of specifying a `From` telephone number in your API request, you specify a Messaging Service SID, its unique identifier.

              In this example, we'll use the Messaging Service SID (It looks like "MGXXX...".) of the Messaging Service that we just created.

                    
                    
                    
                    

                    Run the code sample, replacing the Messaging Service SID ("MGXXX...") and the `To` number with your own mobile phone number (or a friend's!). In a few seconds, you should receive an SMS message!

                    関連トピック

                    Sending an SMS using a Twilio Messaging Service sets you up for efficient scaling. As your messaging needs grow, your Messaging Service will automatically handle the multiple senders in your pool as well as maintain consistent interactions with your end users around the world.

                    Ready to build more? Check out the following resources:

                    Agustin Camino Jarod Reyes David Prothero Kat King Mica Swyers Andrew Baker
                    Rate this page:

                    ヘルプが必要ですか?

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