You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure.Communication.Email预发布版代码挂起问题咨询

问题描述

我注意到Azure.Communication.Email处于预发布阶段,推测可能存在功能异常,但运行以下示例代码时程序直接挂起,请问该服务是否可用?

var connectionString = "endpoint=xxxx";

// Authenticate the client
EmailClient emailClient = new EmailClient(connectionString);

EmailContent emailContent = new EmailContent("Welcome to Azure Communication Service Email APIs.");
emailContent.PlainText = "This email message is sent from Azure Communication Service Email using .NET SDK.";
List<EmailAddress> emailAddresses = new List<EmailAddress> { new EmailAddress("hello@test.com") { DisplayName = "Test Person" } };
EmailRecipients emailRecipients = new EmailRecipients(emailAddresses);
EmailMessage emailMessage = new EmailMessage("donotreply@test.com", emailContent, emailRecipients);

try
{
    SendEmailResult emailResult = emailClient.Send(emailMessage, CancellationToken.None);

}
catch (Exception ex) { Console.WriteLine(string.Format("Error: {0}", ex.Message)); }

Console.WriteLine("Done");

Console.Read(); 
解答

Azure.Communication.Email的预发布(预览)版本是可用的,但存在特定限制,程序挂起通常是代码或配置问题导致,而非服务不可用,排查方向如下:

  • 连接字符串不完整:你的连接字符串仅包含endpoint,缺少accesskey字段。完整格式应为endpoint=https://<resource-name>.communication.azure.com/;accesskey=<your-access-key>,缺失密钥会导致请求无限等待响应,引发挂起。
  • 发件人地址未验证:预览阶段要求发件人邮箱必须是Azure门户中已验证的自定义域名邮箱,或Azure提供的测试域名邮箱。donotreply@test.com属于未验证地址,会导致请求阻塞或静默失败。
  • 同步调用的超时问题:Send同步方法在网络环境不佳时,可能因默认超时过长导致挂起。建议改用异步方法并设置明确超时:
    try
    {
        var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var emailResult = await emailClient.SendAsync(emailMessage, cts.Token);
    }
    catch (OperationCanceledException)
    {
        Console.WriteLine("请求超时");
    }
    catch (Exception ex) 
    { 
        Console.WriteLine($"Error: {ex.Message}"); 
    }
    
  • 网络访问限制:检查本地防火墙、代理是否阻止了程序访问Azure Communication Services的端点,导致请求无法完成。
  • 区域限制:预览版仅在特定区域(如美国东部、西欧)可用,需确保你的ACS资源部署在支持的区域内。

总结:服务本身处于可用状态,优先排查上述配置和代码问题即可解决挂起现象。

内容的提问来源于stack exchange,提问作者matt.whitby

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 02:40:25