我收到此错误“‘Azure.Core.ClientOptions’的类型初始值设定项引发异常”

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

公共静态字符串SendMail(MailInfo邮件) { 字符串 str = "";

    try
    {
        var credentials = new ClientSecretCredential(_tenant, _clientId, _clientSecret, new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud });
        GraphServiceClient graphServiceClient = new GraphServiceClient(credentials);

        var message = new Message
        {
            Subject = mail.Subject,
            Body = new ItemBody
            {
                ContentType = BodyType.Html,
                Content = mail.Message
            },
            ToRecipients = new List<Recipient>()
        {
            new Recipient { EmailAddress = new EmailAddress { Address = mail.ToAddress }}
        }
        };
        graphServiceClient.Users[mail.FromAddress].SendMail(message, true).Request().PostAsync().Wait();

        str = "Success";
    }
    catch (Exception ex)
    {
        str = "Exception";
    }

    return str;

}

这是我的代码。

我在这条线上犯了错误

var 凭据 = new ClientSecretCredential(_tenant, _clientId, _clientSecret, new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud });

在我的日志内的服务器中,我收到此类错误

错误 2022-12-26 12:25:24,250 2186 Registration2 Forgototp - [电子邮件受保护] 错误 2022-12-26 12:25:24,297 2233 MailHelper SendForgetPassword - SendForgetPassword:[电子邮件受保护] 7472 阿明 错误 2022-12-26 12:25:24,313 2249 MailHelper SendForgetPassword - “Azure.Core.ClientOptions”的类型初始值设定项引发异常。

在 Azure.Identity.TokenCredentialOptions..ctor() 在 C:\Users\ABI-Tech Tele-Call\Downloads\DigitalID Latest\ABIWHIZ\Helpers\MailHelper.cs 中的 ABIWHIZ.MailHelper.SendMail(MailInfo 邮件):第 360 行 在 C:\Users\ABI-Tech Tele-Call\Downloads\DigitalID Latest\ABIWHIZ\Helpers\MailHelper.cs 中的 ABIWHIZ.MailHelper.SendForgetPassword(字符串电子邮件、字符串密码、字符串名称):第 287 行

请帮助我完成我的任务

asp.net asp.net-mvc model-view-controller
1个回答
0
投票

你尝试过吗

var credentials = new ClientSecretCredential(_tenant, _clientId, _clientSecret);
一直在为我工作

© www.soinside.com 2019 - 2024. All rights reserved.