惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
A
About on SuperTechFans
U
Unit 42
MyScale Blog
MyScale Blog
J
Java Code Geeks
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
D
Docker
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
量子位
月光博客
月光博客
G
Google Developers Blog
V
V2EX
博客园 - 聂微东
宝玉的分享
宝玉的分享
IT之家
IT之家
Vercel News
Vercel News

博客园 - 启明星工作室

高等数学在线入门教程(零基础适配) Latex安装Texlive Authenticate an EWS application by using OAuth codemirror 高等数学课件 线性代数课件 概率论与数理统计课件 C# String 字符串转换为base64 C#语言async, await 简单介绍与实例(入门级) Microsoft.Exchange.WebServices.Data; 启明星工作室网站改版了 dotnetcms.cn 数学题库管理系统 Math 面向老师的单机版“数学系统math” 启明星Helpdesk系统,欢迎大家使用。 启明星人物评选投票系统,欢迎大家使用 微信安装包从0.5M暴涨到260M,为什么我们的程序越来越大? Kmath里MathJax和markdown整合 Windows下TeXLive 环境的安装与配置 MathPix
使用 Microsoft Graph oFFICE365 sendmail C#
启明星工作室 · 2024-01-11 · via 博客园 - 启明星工作室

using Microsoft.Graph;
using Azure.Identity;
using Microsoft.Graph.Models;

var scopes = new[] { "https://graph.microsoft.com/.default" };

var tenantId = "{tenant id}";

// Values from app registration
var clientId = "{client id}";
var clientSecret = "{client secret}";

// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);

var accessToken = await clientSecretCredential.GetTokenAsync(new Azure.Core.TokenRequestContext(scopes) { });

Console.WriteLine(accessToken.Token);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);

var requestBody = new Microsoft.Graph.Users.Item.SendMail.SendMailPostRequestBody
{
Message = new Message
{
Subject = "Meet for lunch?",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "The new cafeteria is open.",
},
ToRecipients = new List
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "xxxx@xxxxxxxxxxx",
},
},
},
},
SaveToSentItems = false,
};

await graphClient.Users["{user id}"].SendMail.PostAsync(requestBody);