Comment intégrer une image en ligne dans le corps d’un e-mail avec Microsoft Graph
J’ai écrit une démo pour vous, essayez l’application console simple ci-dessous :
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
namespace sendEmails
{
class Program
{
static void Main(string[] args)
{
var appID = "";
var appSec = "";
var tenantID = "";
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(appID)
.WithTenantId(tenantID)
.WithClientSecret(appSec)
.Build();
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphServiceClient = new GraphServiceClient(authenticationProvider);
var imagePath = @"<your image path>";
var imageID = "image1";
byte[] imageArray = System.IO.File.ReadAllBytes(imagePath);
var body = "<h1>this is superman </br> <img src='cid:"+ imageID + "'/></h1>";
var attachments = new MessageAttachmentsCollectionPage()
{
new FileAttachment{
ContentType= "image/jpeg",
ContentBytes = imageArray,
ContentId = imageID,
Name= "test-image"
}
};
var message = new Message
{
Subject = "TEST SENDING IMAGE ",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = body,
ODataType = null
},
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
*(Réponse tronquée)*