简体   繁体   English

使用C#Winforms在twilio中发送批量SMS

[英]Send bulk SMS in twilio using C# Winforms

I need to know how do I send a bulk SMS using Twilio API and C#.I did some research which also show that I need to use Twilio's Passthrough API, but I fail to understand it. 我需要知道如何使用Twilio API和C#发送批量SMS,还做了一些研究表明我需要使用Twilio的Passthrough API,但我不理解它。 Here is the code I compiled: 这是我编译的代码:

const string accountSid = "xxxxx";
const string authToken = "xxxxx";

TwilioClient.Init(accountSid, authToken);

MessageResource.Create(to: new PhoneNumber("+27" + txtTo.Text),
                       from: new PhoneNumber("xxxxx"),
                       body: txtMessage.Text,
                       provideFeedback: true,
                       statusCallback: new Uri("http://requestb.in/1234abcd"));

MessageBox.Show("Message sent successfully");

You can't do this way. 你不能这样。 You have to loop through your subscribers list and send it one by one or by using a parallel foreach : 您必须遍历订户列表,并一一发送,或使用并行的foreach将其发送:

var subscriber = new Dictionary<string, string>() {
            {"+3912345678", "John"},
            {"+3917564237", "Mark"},
            {"+3915765311", "Ester"}
        };

// Iterate over subscribers
foreach (var person in subscriber)
{
    // Send a new outgoing SMS by POSTing to the Messages resource
    MessageResource.Create(
        from: new PhoneNumber("555-555-5555"), // From number, must be an SMS-enabled Twilio number
        to: new PhoneNumber(person.Key), // To number, if using Sandbox see note above
        // Message content
        body: $"Hello {person.Value}");

    Console.WriteLine($"Sent message to {person.Value}");
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM