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

推荐订阅源

C
Check Point Blog
Y
Y Combinator Blog
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
博客园_首页
大猫的无限游戏
大猫的无限游戏
美团技术团队
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
小众软件
小众软件
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
N
Netflix TechBlog - Medium
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园 - 【当耐特】
J
Java Code Geeks
F
Fortinet All Blogs
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美

博客园 - 启明星工作室

高等数学在线入门教程(零基础适配) 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);