使用 C# Winforms 在 twilio 中发送批量短信
Send bulk SMS in twilio using C# Winforms
我需要知道如何使用 Twilio API 和 C# 发送群发短信。我做了一些研究,结果还表明我需要使用 Twilio 的直通 API,但我没能做到明白它。这是我编译的代码:
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");
你不能这样做。您必须 遍历订阅者 列表并逐一发送或使用 parallel 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}");
}
我需要知道如何使用 Twilio API 和 C# 发送群发短信。我做了一些研究,结果还表明我需要使用 Twilio 的直通 API,但我没能做到明白它。这是我编译的代码:
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");
你不能这样做。您必须 遍历订阅者 列表并逐一发送或使用 parallel 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}");
}