当前位置: 首页 > news >正文

永康住房和城乡建设部网站必应搜索引擎

永康住房和城乡建设部网站,必应搜索引擎,中企动力官网邮箱,厦门微网站建设公司一、背景说明 在已有的项目中,已经获取到了Graph的AccessToken并保存在内存里面。所以不希望再通过client secret或者certificate去创建GraphServiceClient对象。希望使用现有的token字符串来创建初始化创建GraphServiceClient从而来实现Graph其他API功能。 二、具体…
一、背景说明

在已有的项目中,已经获取到了Graph的AccessToken并保存在内存里面。所以不希望再通过client secret或者certificate去创建GraphServiceClient对象。希望使用现有的token字符串来创建初始化创建GraphServiceClient从而来实现Graph其他API功能。

二、具体实现

2.1 需要Java Graph SDK依赖 加入到pom.xml文件内

 <!-- Microsoft Graph SDK for Java --><dependency><groupId>com.microsoft.graph</groupId><artifactId>microsoft-graph</artifactId><version>[5.0,)</version></dependency><!-- Azure AD Authentication SDK for Java --><dependency><groupId>com.azure</groupId><artifactId>azure-identity</artifactId><version>[1.3,)</version></dependency>

2.2 代码片段

  public static GraphServiceClient initGraphServiceClient() {IAuthenticationProvider authProvider = new IAuthenticationProvider() {@Overridepublic CompletableFuture<String> getAuthorizationTokenAsync(URL requestUrl) {CompletableFuture<String> future = new CompletableFuture<>();future.complete(Your_AccessToken);return future;}};return GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();}
三、测试

下面代码是实现调用创建GraphServiceClient,调用graph api发送带附件的邮件。

	public static String sendMail() {try {String mfrom = "xxxx@outlook.com";String to = "xxxx@outlook.com";GraphServiceClient<Request> graphClient = initGraphServiceClient();Message message = new Message();message.subject = "Meet for lunch?";ItemBody body = new ItemBody();body.contentType = BodyType.TEXT;body.content = "The new cafeteria is open.";message.body = body;LinkedList<Recipient> toRecipientsList = new LinkedList<Recipient>();Recipient toRecipients = new Recipient();EmailAddress emailAddress = new EmailAddress();emailAddress.address = to;toRecipients.emailAddress = emailAddress;toRecipientsList.add(toRecipients);message.toRecipients = toRecipientsList;// 构建附件LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();FileAttachment attachments = new FileAttachment();attachments.name = "hello word.txt";attachments.oDataType = "#microsoft.graph.fileAttachment";attachments.contentType = "text/plain";attachments.contentBytes = Base64.getDecoder().decode("SGVsbG8gV29ybGQh");attachmentsList.add(attachments);AttachmentCollectionResponse attachmentCollectionResponse = new AttachmentCollectionResponse();attachmentCollectionResponse.value = attachmentsList;AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage(attachmentCollectionResponse, null);message.attachments = attachmentCollectionPage;// 以指定用户邮箱发送邮件graphClient.users(mfrom).sendMail(UserSendMailParameterSet.newBuilder().withMessage(message).withSaveToSentItems(true).build()).buildRequest().post();log.info("send email success");return "success";} catch (Exception e) {e.printStackTrace();log.error("send email error : {}", e.getMessage());return e.getMessage();}}

http://www.tj-hxxt.cn/news/88175.html

相关文章:

  • seo是干啥的百度关键字优化价格
  • 垂直网站建设关键词排名查询网站
  • 有什么好的建站公司西安seo网站建设
  • 外贸网站推广和建站网站宣传方法
  • wordpress外网排版问题seo排名赚app官网
  • 团购网站app制作seo网站优化怎么做
  • 聊城集团网站建设价格企业网站推广的方法有哪些
  • 网站开发需要哪些知识学生个人网页优秀模板
  • 销售网站开发cms快速建站
  • 网站中点击链接怎么做优秀企业网站模板
  • 做的很好的画册网站宁波网站推广方案
  • 免费的求职简历模板网站微信管理系统平台
  • 淘宝客网站应该怎么做搜关键词网站
  • 一 网站建设的目的和目标seo索引擎优化
  • 免费建站哪里找搜索引擎优化seo专员招聘
  • 专做机票网站的软件公司产品运营主要做什么
  • 肯德基网站建设seo排名赚app多久了
  • 宝鸡商城网站开发什么是交换链接
  • 合肥 网站建设2345网址导航电脑版官网
  • 廊坊专业网站建设网上教育培训机构排名
  • 西安企业建站公司如何创建个人网页
  • 网站一跳率重庆网站推广联系方式
  • 麻城网站制作公司河北企业网站建设
  • 网站开发使用软件公司网站页面设计
  • 网站建设基础教程视频网络广告的概念
  • 自己做游戏的网站电商从零基础怎么学
  • 冠县网站建设江苏泰州seo网络优化推广
  • qq客服代码 wordpress南宁seo推广公司
  • 中国监理建设协会网站百度搜索风云榜电脑版
  • 京东购物中心优化