Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #53 from juanpescador/fix-uncaught-exception-send-…
Browse files Browse the repository at this point in the history
…email

Fix uncaught exception when sending email
  • Loading branch information
mark-szabo authored Oct 7, 2019
2 parents 03267f8 + e4078a7 commit 8870a81
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,21 @@ public static async Task SendEmail(GraphServiceClient graphClient, IHostingEnvir
// Load user's profile picture.
var pictureStream = await GetMyPictureStream(graphClient, httpContext);

// Copy stream to MemoryStream object so that it can be converted to byte array.
var pictureMemoryStream = new MemoryStream();
await pictureStream.CopyToAsync(pictureMemoryStream);

// Convert stream to byte array and add as attachment.
attachments.Add(new FileAttachment
if (pictureStream != null)
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = pictureMemoryStream.ToArray(),
ContentType = "image/png",
Name = "me.png"
});
// Copy stream to MemoryStream object so that it can be converted to byte array.
var pictureMemoryStream = new MemoryStream();
await pictureStream.CopyToAsync(pictureMemoryStream);

// Convert stream to byte array and add as attachment.
attachments.Add(new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = pictureMemoryStream.ToArray(),
ContentType = "image/png",
Name = "me.png"
});
}
}
catch (Exception e)
{
Expand Down

0 comments on commit 8870a81

Please sign in to comment.