diff --git a/src/Senders/FluentEmail.Graph/FluentEmail.Graph.csproj b/src/Senders/FluentEmail.Graph/FluentEmail.Graph.csproj index c8695580..847d97e8 100644 --- a/src/Senders/FluentEmail.Graph/FluentEmail.Graph.csproj +++ b/src/Senders/FluentEmail.Graph/FluentEmail.Graph.csproj @@ -9,9 +9,8 @@ - - - + + diff --git a/src/Senders/FluentEmail.Graph/GraphSender.cs b/src/Senders/FluentEmail.Graph/GraphSender.cs index 963ee65a..e5d0bbb2 100644 --- a/src/Senders/FluentEmail.Graph/GraphSender.cs +++ b/src/Senders/FluentEmail.Graph/GraphSender.cs @@ -1,9 +1,10 @@ -using FluentEmail.Core; +using Azure.Identity; +using FluentEmail.Core; using FluentEmail.Core.Interfaces; using FluentEmail.Core.Models; using Microsoft.Graph; -using Microsoft.Graph.Auth; -using Microsoft.Identity.Client; +using Microsoft.Graph.Models; +using Microsoft.Graph.Users.Item.SendMail; using System; using System.Collections.Generic; using System.IO; @@ -19,9 +20,7 @@ public class GraphSender : ISender private readonly string _graphSecret; private bool _saveSent; - private ClientCredentialProvider _authProvider; private GraphServiceClient _graphClient; - private IConfidentialClientApplication _clientApp; public GraphSender( string GraphEmailAppId, @@ -34,15 +33,8 @@ public GraphSender( _graphSecret = GraphEmailSecret; _saveSent = SaveSentItems; - _clientApp = ConfidentialClientApplicationBuilder - .Create(_appId) - .WithTenantId(_tenantId) - .WithClientSecret(_graphSecret) - .Build(); - - _authProvider = new ClientCredentialProvider(_clientApp); - - _graphClient = new GraphServiceClient(_authProvider); + var credential = new ClientSecretCredential(_tenantId, _appId, _graphSecret); + _graphClient = new GraphServiceClient(credential); } public SendResponse Send(IFluentEmail email, CancellationToken? token = null) @@ -77,7 +69,7 @@ public async Task SendAsync(IFluentEmail email, CancellationToken? email.Data.ToAddresses.ForEach(r => toRecipients.Add(new Recipient { EmailAddress = new EmailAddress - { + { Address = r.EmailAddress.ToString(), Name = r.Name } @@ -120,7 +112,7 @@ public async Task SendAsync(IFluentEmail email, CancellationToken? if(email.Data.Attachments != null && email.Data.Attachments.Count > 0) { - message.Attachments = new MessageAttachmentsCollectionPage(); + message.Attachments = new List(); email.Data.Attachments.ForEach(a => { @@ -154,9 +146,12 @@ public async Task SendAsync(IFluentEmail email, CancellationToken? try { await _graphClient.Users[email.Data.FromAddress.EmailAddress] - .SendMail(message, _saveSent) - .Request() - .PostAsync(); + .SendMail + .PostAsync(new SendMailPostRequestBody + { + Message = message, + SaveToSentItems = _saveSent + }, cancellationToken: token ?? CancellationToken.None); return new SendResponse {