如何在 c# 中使用 Azure 通信服务 SMS 发送多个收件人 SMS

问题描述 投票:0回答:0

我正在开发小型 Web 应用程序以使用 Azure 通信服务为多个收件人发送短信。我从微软官方页面获得了以下代码,它适用于一个收件人。

SmsClient smsClient = new SmsClient(connectionString);

        SmsSendResult sendResult = smsClient.Send(
            from: sms.From.ToString(),
            to: sms.To.ToString(),
            message: sms.Body,
            options: new SmsSendOptions(enableDeliveryReport: true) { }
        ) ; 

如果我将收件人列表传递给显示语法错误的“收件人”。

短信.cs

`public class SMS 
    {
         public SMS() { }

        public SMS(SMS sms)
        {
            if (sms == null)
                throw new ArgumentNullException(nameof(sms));

            From = sms.From;
            To = sms.To;
            Body = sms.Body;
        }

        [DataType(DataType.PhoneNumber)]
        public string From { get; set; }
       
        public string Body { get; set; }
       
        [DataType(DataType.PhoneNumber)]
        public string[] To { get; set; }
    }`

我修改了如下代码

 List<SmsSendResult> sendResult = (List<SmsSendResult>) smsClient.Send(
            from: sms.From,
            to: sms.To,
            message: sms.Body,
            options: new SmsSendOptions(enableDeliveryReport: true) { }
        ) ;

错误是

有人可以帮忙吗?

c# azure asp.net-core sms azure-communication-services
© www.soinside.com 2019 - 2024. All rights reserved.