Код: Выделить всё
static async Task SendEmail()
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = ""; // Replace with your Tenant ID
var clientId = ""; // Replace with Application ID from Overview tab
var clientSecret = ""; // Replace with the Client Secret
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var message = new Message
{
Subject = "This is the subject line",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "This is the body of the email message."
},
ToRecipients = new List
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "user@domain.com" // This is the recipient of the message
}
}
}
};
await graphClient.Users["myuser@mydomain.com"].SendMail(message, null).Request().PostAsync();
}
Код: Выделить всё
Severity Code Description Project File Line Suppression State
Error CS1955 Non-invocable member 'UserItemRequestBuilder.SendMail' cannot be used like a method. MailSend
Код: Выделить всё
await graphClient.Users["myuser@mydomain.com"].SendMail(message, null).Request().PostAsync();
И это по сути тот же код. Похоже, что в предыдущих версиях код был правильным.
Я понимаю суть того, о чем говорит мне ошибка, но я недостаточно разбираюсь в .net и Graph SDK, чтобы ее исправить.
Любая помощь и объяснения очень ценятся.
РЕДАКТИРОВАТЬ
Я понизил SDK до Graph 4 и следующий код не сообщает об ошибках, но он не работает.
Код: Выделить всё
using Azure.Identity;
using Microsoft.Graph;
namespace MailSend1
{
internal class Program
{
static void Main(string[] args)
{
await SendEmail();
}
public static async Task SendEmail()
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = ""; // Replace with your Tenant ID
var clientId = ""; // Replace with Application ID from Overview tab
var clientSecret = ""; // Replace with the Client Secret
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var message = new Message
{
Subject = "Just a test!",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Does it work?"
},
ToRecipients = new List
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "someuser@gmail.com" // This is the recipient of the message
}
}
}
};
Console.WriteLine("Mail TO BE sent!");
bool saveToSentItems = true;
// Specify the user account to send from. An account in your tenant. It also sends the email.
await graphClient.Users["test@somedomain.net"].SendMail(message, saveToSentItems).Request().PostAsync();
Console.WriteLine("Mail sent!");
}
}
}
Кроме того, второй оператор строки записи никогда не печатается.
Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/772 ... rk-anymore
Мобильная версия