<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Now Getting error in SAS Viya</title>
    <link>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/894220#M2011</link>
    <description>&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;ERROR&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{"error":{"code":"OrganizationFromTenantGuidNotFound","message":"The tenant for tenant guid '0e888a36-e21e-42e0-9cd2-bed9a933d9ee' d&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oes not exist.","innerError":{"oAuthEventOperationId":"173eae30-7d2d-47fe-a7c2-89eaea6d822c","oAuthEventcV":"4BaJutuPZOOnZzJRr+gHNg.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1.1.1","errorUrl":"&lt;/SPAN&gt;&lt;A href="https://aka.ms/autherrors#error-InvalidTenant%22,%22requestId%22:%22434b4ffd-4897-4dd0-84db-9b6cfd211a69%22,%22date%22:%222023-09" target="_blank" rel="noopener"&gt;https://aka.ms/autherrors#error-InvalidTenant","requestId":"434b4ffd-4897-4dd0-84db-9b6cfd211a69","date":"2023-09&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;-13T05:16:41"}}}&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;After a Modified Code&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro to process the JSON token&lt;BR /&gt;file that was created at authorization time.&lt;BR /&gt;This will fetch the access token, refresh token,&lt;BR /&gt;and expiration datetime for the token so we know&lt;BR /&gt;if we need to refresh it.&lt;BR /&gt;*/&lt;BR /&gt;%macro process_token_file(file);&lt;BR /&gt;libname oauth json fileref=&amp;amp;file.;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set oauth.root;&lt;BR /&gt;call symputx('access_token', access_token,'G');&lt;BR /&gt;call symputx('refresh_token', refresh_token,'G');&lt;BR /&gt;/* convert epoch value to SAS datetime */&lt;BR /&gt;call symputx('expires_on',(input(expires_on,best32.)+'01jan1970:00:00'dt),'G');&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro that retrieves the initial access token&lt;BR /&gt;by redeeming the authorization code that you're granted&lt;BR /&gt;during the interactive step using a web browser&lt;BR /&gt;while signed into your Microsoft OneDrive / Azure account.&lt;/P&gt;&lt;P&gt;This step also creates the initial token.json that will be&lt;BR /&gt;used on subsequent steps/sessions to redeem a refresh token.&lt;BR /&gt;*/&lt;BR /&gt;%macro get_token(client_id,&lt;BR /&gt;client_secret,&lt;BR /&gt;code,&lt;BR /&gt;scope,&lt;BR /&gt;outfile,&lt;BR /&gt;redirect_uri=&lt;A href="https://deployopt.demo.com/SASLogon/login/callback/azure" target="_blank"&gt;https://deployopt.demo.com/SASLogon/login/callback/azure&lt;/A&gt;,&lt;BR /&gt;tenant=0e888a36-e21e-42e0-9cd2-bed9a933d9ee,&lt;BR /&gt;debug=0);&lt;/P&gt;&lt;P&gt;proc http url="&lt;A href="https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token" target="_blank"&gt;https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token&lt;/A&gt;"&lt;BR /&gt;method="POST"&lt;BR /&gt;in="%nrstr(&amp;amp;client_id)=&amp;amp;client_id.%nrstr(&amp;amp;client_secret)=&amp;amp;client_secret.%nrstr(&amp;amp;code)=&amp;amp;code.%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri%nrstr(&amp;amp;grant_type)=authorization_code%nrstr(&amp;amp;scope)=&amp;amp;scope."&lt;BR /&gt;out=&amp;amp;outfile.;&lt;BR /&gt;%if &amp;amp;debug&amp;gt;=0 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;debug.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if &amp;amp;_DEBUG_. ge 1 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;_DEBUG_.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%process_token_file(&amp;amp;outfile);&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro to redeem the refresh token&lt;BR /&gt;and get a new access token for use in subsequent&lt;BR /&gt;calls to the OneDrive service.&lt;BR /&gt;*/&lt;BR /&gt;%macro refresh(client_id,&lt;BR /&gt;client_secret,&lt;BR /&gt;refresh_token,&lt;BR /&gt;scope,&lt;BR /&gt;outfile,&lt;BR /&gt;redirect_uri=&lt;A href="https://deployopt.demo.com/SASLogon/login/callback/azure" target="_blank"&gt;https://deployopt.demo.com/SASLogon/login/callback/azure&lt;/A&gt;,&lt;BR /&gt;tenant=common,&lt;BR /&gt;debug=0);&lt;/P&gt;&lt;P&gt;proc http url="&lt;A href="https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token" target="_blank"&gt;https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token&lt;/A&gt;"&lt;BR /&gt;method="POST"&lt;BR /&gt;in="%nrstr(&amp;amp;client_id)=&amp;amp;client_id.%nrstr(&amp;amp;client_secret)=&amp;amp;client_secret.%nrstr(&amp;amp;refresh_token=)&amp;amp;refresh_token%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;grant_type)=refresh_token%nrstr(&amp;amp;scope)=&amp;amp;scope."&lt;BR /&gt;out=&amp;amp;outfile.;&lt;BR /&gt;%if &amp;amp;debug. ge 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;debug.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %symexist(_DEBUG_) AND &amp;amp;_DEBUG_. ge 1 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;_DEBUG_.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%process_token_file(&amp;amp;outfile);&lt;BR /&gt;%mend refresh;&lt;BR /&gt;&lt;BR /&gt;/* generate Token */&lt;/P&gt;&lt;DIV&gt;%let config_root=/sasdata;&lt;/DIV&gt;&lt;DIV&gt;%if %symexist(config_root) %then %do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; filename config "&amp;amp;config_root./config.json";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; libname config json fileref=config;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; data _null_;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;set config.root;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('tenant_id',tenant_id,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('client_id',client_id,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('redirect_uri',redirect_uri,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('client_secret',client_secret,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('scope',scope,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; run;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;%else %do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; %put ERROR: You must define the CONFIG_ROOT macro variable.;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%let authorize_url=&lt;A href="https://login.microsoftonline.com/&amp;amp;tenant_id./oauth2/v2.0/authorize?client_id=&amp;amp;client_id.%nrstr(&amp;amp;response_type)=code%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;scope)=&amp;amp;scope" target="_blank"&gt;https://login.microsoftonline.com/&amp;amp;tenant_id./oauth2/v2.0/authorize?client_id=&amp;amp;client_id.%nrstr(&amp;amp;response_type)=code%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;scope)=&amp;amp;scope&lt;/A&gt;.;&lt;/DIV&gt;&lt;DIV&gt;options nosource;&lt;/DIV&gt;&lt;DIV&gt;%put Paste this URL into your web browser:;&lt;/DIV&gt;&lt;DIV&gt;%put -- START -------;&lt;/DIV&gt;&lt;DIV&gt;%put &amp;amp;authorize_url;&lt;/DIV&gt;&lt;DIV&gt;%put ---END ---------;&lt;/DIV&gt;&lt;DIV&gt;options source;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename token "&amp;amp;config_root./token.json";&lt;/DIV&gt;&lt;DIV&gt;%let auth_code=0.ASsANoqIDh7i4EKc0r7ZqTPZ7jwymLltqM1Ao9E-7URpiinCAAA.AgABAAIAAAAtyolDObpQQ5VtlI4uGjEPAgDs_wUA9P-O2Dj3uaJl1brAZnNrFCJl0Hbmyd-N3gb2ToMjb4L5Xd8LSegqzaKJ1hajRaRrCmvxtFsBeNe-ukY7q8ZOGOu5iOMZFsUm8sBzLX6gYc_5KECWoNNwOMj5szizeiryEpfSlArSy1P2uq9mzfmn-umXIEyOqh73Tuo48hNWhfgHgAzFZSGw5u4Pe-0wxnyByueERkxo6qI8AZVWDsoppwsFDwxX0RTI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*&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; Now that we have an authorization code we can get the access token&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; This step will write the tokens.json file that we can use in our&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; production programs.&lt;/DIV&gt;&lt;DIV&gt;*/&lt;/DIV&gt;&lt;DIV&gt;%get_token(&amp;amp;client_id.,&amp;amp;client_secret.,&amp;amp;auth_code,&amp;amp;scope.,token,tenant=&amp;amp;tenant_id);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename token "&amp;amp;config_root./token.json";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%process_token_file(token);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* If this is first use for the session, we'll likely need to refresh&amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;/* the token.&amp;nbsp; This will also call process_token_file again and update */&lt;/DIV&gt;&lt;DIV&gt;/* our token.json file.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;%refresh(&amp;amp;client_id.,&amp;amp;refresh_token.,&amp;amp;resource.,token,tenant=&amp;amp;tenant_id.);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename resp TEMP;&lt;/DIV&gt;&lt;DIV&gt;/* Note: oauth_bearer option added in 9.4M5 */&lt;/DIV&gt;&lt;DIV&gt;proc http url="&lt;A href="https://graph.microsoft.com/v1.0/me/sendMail" target="_blank"&gt;https://graph.microsoft.com/v1.0/me/sendMail&lt;/A&gt;"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;oauth_bearer="&amp;amp;access_token"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;out = resp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;libname jresp json fileref=resp;&lt;BR /&gt;&lt;BR /&gt;/* send MAil*/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;%let EMAIL_ADDRESS = shivraj.pawar@woodpeckerind.com;&lt;BR /&gt;filename send temp;&lt;BR /&gt;data null;&lt;BR /&gt;file send;&lt;BR /&gt;put '{"message": {'&lt;BR /&gt;'"subject": "Test Email",'&lt;BR /&gt;'"body": {'&lt;BR /&gt;'"contentType": "Text",'&lt;BR /&gt;'"content": "This is a test email."'&lt;BR /&gt;'},'&lt;BR /&gt;'"toRecipients": ['&lt;BR /&gt;'{'&lt;BR /&gt;'"emailAddress": {'&lt;BR /&gt;'"address": "' "&amp;amp;EMAIL_ADDRESS." '"'&lt;BR /&gt;'}'&lt;BR /&gt;'}'&lt;BR /&gt;']'&lt;BR /&gt;'}}';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;filename resp temp;&lt;BR /&gt;proc http&lt;BR /&gt;method="POST"&lt;BR /&gt;url="&lt;A href="https://graph.microsoft.com/v1.0/me/sendMail" target="_blank"&gt;https://graph.microsoft.com/v1.0/me/sendMail&lt;/A&gt;"&lt;BR /&gt;in=send&lt;BR /&gt;out=resp; /* Store the response in a file */&lt;BR /&gt;headers "Content-Type"="application/json"&lt;BR /&gt;"Authorization"="Bearer &amp;amp;access_token.";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Check the response for success or error */&lt;BR /&gt;data _null_;&lt;BR /&gt;infile resp;&lt;BR /&gt;input;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Sep 2023 06:20:01 GMT</pubDate>
    <dc:creator>Rutujak</dc:creator>
    <dc:date>2023-09-14T06:20:01Z</dc:date>
    <item>
      <title>Iam trying to Send ,read mail thorugh  sas code using Microsoft Graph</title>
      <link>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/892840#M2000</link>
      <description>&lt;DIV&gt;&lt;P&gt;/* ----------------------------------------------------&lt;BR /&gt;Utility macros to manage and refresh the access token&lt;BR /&gt;for using Microsoft OneDrive APIs from SAS,&lt;BR /&gt;using PROC HTTP.&lt;/P&gt;&lt;P&gt;Authors: Joseph Henry, SAS&lt;BR /&gt;Chris Hemedinger, SAS&lt;BR /&gt;Copyright 2018, SAS Institute Inc.&lt;BR /&gt;-------------------------------------------------------*/&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro to process the JSON token&lt;BR /&gt;file that was created at authorization time.&lt;BR /&gt;This will fetch the access token, refresh token,&lt;BR /&gt;and expiration datetime for the token so we know&lt;BR /&gt;if we need to refresh it.&lt;BR /&gt;*/&lt;BR /&gt;%macro process_token_file(file);&lt;BR /&gt;libname oauth json fileref=&amp;amp;file.;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set oauth.root;&lt;BR /&gt;call symputx('access_token', access_token,'G');&lt;BR /&gt;call symputx('refresh_token', refresh_token,'G');&lt;BR /&gt;/* convert epoch value to SAS datetime */&lt;BR /&gt;call symputx('expires_on',(input(expires_on,best32.)+'01jan1970:00:00'dt),'G');&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro that retrieves the initial access token&lt;BR /&gt;by redeeming the authorization code that you're granted&lt;BR /&gt;during the interactive step using a web browser&lt;BR /&gt;while signed into your Microsoft OneDrive / Azure account.&lt;/P&gt;&lt;P&gt;This step also creates the initial token.json that will be&lt;BR /&gt;used on subsequent steps/sessions to redeem a refresh token.&lt;BR /&gt;*/&lt;BR /&gt;%macro get_token(client_id,&lt;BR /&gt;code,&lt;BR /&gt;resource,&lt;BR /&gt;outfile,&lt;BR /&gt;redirect_uri=&lt;A href="https://login.microsoftonline.com/common/oauth2/nativeclient" target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/common/oauth2/nativeclient&lt;/A&gt;,&lt;BR /&gt;tenant=common,&lt;BR /&gt;debug=0);&lt;/P&gt;&lt;P&gt;proc http url="&lt;A href="https://login.microsoft.com/&amp;amp;tenant_id./oauth2/token" target="_blank" rel="noopener"&gt;https://login.microsoft.com/&amp;amp;tenant_id./oauth2/token&lt;/A&gt;"&lt;BR /&gt;method="POST"&lt;BR /&gt;in="%nrstr(&amp;amp;client_id)=&amp;amp;client_id.%nrstr(&amp;amp;code)=&amp;amp;code.%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri%nrstr(&amp;amp;grant_type)=authorization_code%nrstr(&amp;amp;resource)=&amp;amp;resource."&lt;BR /&gt;out=&amp;amp;outfile.;&lt;BR /&gt;%if &amp;amp;debug&amp;gt;=0 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;debug.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if &amp;amp;_DEBUG_. ge 1 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;_DEBUG_.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%process_token_file(&amp;amp;outfile);&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro to redeem the refresh token&lt;BR /&gt;and get a new access token for use in subsequent&lt;BR /&gt;calls to the OneDrive service.&lt;BR /&gt;*/&lt;BR /&gt;%macro refresh(client_id,&lt;BR /&gt;refresh_token,&lt;BR /&gt;resource,&lt;BR /&gt;outfile,&lt;BR /&gt;redirect_uri=&lt;A href="https://login.microsoftonline.com/common/oauth2/nativeclient" target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/common/oauth2/nativeclient&lt;/A&gt;,&lt;BR /&gt;tenant=common,&lt;BR /&gt;debug=0);&lt;/P&gt;&lt;P&gt;proc http url="&lt;A href="https://login.microsoft.com/&amp;amp;tenant_id./oauth2/token" target="_blank" rel="noopener"&gt;https://login.microsoft.com/&amp;amp;tenant_id./oauth2/token&lt;/A&gt;"&lt;BR /&gt;method="POST"&lt;BR /&gt;in="%nrstr(&amp;amp;client_id)=&amp;amp;client_id.%nrstr(&amp;amp;refresh_token=)&amp;amp;refresh_token%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;grant_type)=refresh_token%nrstr(&amp;amp;resource)=&amp;amp;resource."&lt;BR /&gt;out=&amp;amp;outfile.;&lt;BR /&gt;%if &amp;amp;debug. ge 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;debug.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %symexist(_DEBUG_) AND &amp;amp;_DEBUG_. ge 1 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;_DEBUG_.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%process_token_file(&amp;amp;outfile);&lt;BR /&gt;%mend refresh;&lt;/P&gt;&lt;BR /&gt;%let config_root=/sasdata;&lt;/DIV&gt;&lt;DIV&gt;%if %symexist(config_root) %then %do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; filename config "&amp;amp;config_root./config.json";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; libname config json fileref=config;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; data _null_;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;set config.root;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('tenant_id',tenant_id,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('client_id',client_id,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('redirect_uri',redirect_uri,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('resource',resource,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; run;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;%else %do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; %put ERROR: You must define the CONFIG_ROOT macro variable.;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%let authorize_url=&lt;A href="https://login.microsoftonline.com/&amp;amp;tenant_id./oauth2/authorize?client_id=&amp;amp;client_id.%nrstr(&amp;amp;response_type)=code%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;resource)=&amp;amp;resource" target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/&amp;amp;tenant_id./oauth2/authorize?client_id=&amp;amp;client_id.%nrstr(&amp;amp;response_type)=code%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;resource)=&amp;amp;resource&lt;/A&gt;.;&lt;/DIV&gt;&lt;DIV&gt;options nosource;&lt;/DIV&gt;&lt;DIV&gt;%put Paste this URL into your web browser:;&lt;/DIV&gt;&lt;DIV&gt;%put -- START -------;&lt;/DIV&gt;&lt;DIV&gt;%put &amp;amp;authorize_url;&lt;/DIV&gt;&lt;DIV&gt;%put ---END ---------;&lt;/DIV&gt;&lt;DI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PLbuzIxRSCdavLnJ8f-mo1SMo4ET9mIgvtr2GfmBHsHSVbeIZKd62ZMZ_uQb-EDqWb2gDGbWZ0nJWFMxPkA0dGI-8zxN9EgzkH6Layj2koNf1d7tXy4dDGu0cu4dhGFW-DIA7ObZJF8ixNO_sA6Wt_uDa20uY78jTpkjf3uM2Qw0YP0rZSkNcA7TgqLM3Hgk0uTslPtCoElXZbMu7tuocuEULWRz38fj7vrff1LuOVEZ8fHfjB1TJ_iP7KMBO7dd5bCN5Wdd5njGQZMtoSw;&lt;/DIV&gt;&lt;DIV&gt;/*&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; Now that we have an authorization code we can get the access token&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; This step will write the tokens.json file that we can use in our&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; production programs.&lt;/DIV&gt;&lt;DIV&gt;*/&lt;/DIV&gt;&lt;DIV&gt;%get_token(&amp;amp;client_id.,&amp;amp;auth_code,&amp;amp;resource.,token,tenant=&amp;amp;tenant_id);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename token "&amp;amp;config_root./token.json";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%process_token_file(token);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* If this is first use for the session, we'll likely need to refresh&amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;/* the token.&amp;nbsp; This will also call process_token_file again and update */&lt;/DIV&gt;&lt;DIV&gt;/* our token.json file.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;%refresh(&amp;amp;client_id.,&amp;amp;refresh_token.,&amp;amp;resource.,token,tenant=&amp;amp;tenant_id.);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename resp TEMP;&lt;/DIV&gt;&lt;DIV&gt;/* Note: oauth_bearer option added in 9.4M5 */&lt;/DIV&gt;&lt;DIV&gt;proc http url="&lt;A href="https://graph.microsoft.com/v1.0/me/sendMail" target="_blank" rel="noopener"&gt;https://graph.microsoft.com/v1.0/me/sendMail&lt;/A&gt;"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;oauth_bearer="&amp;amp;access_token"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;out = resp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;libname jresp json fileref=resp;&lt;BR /&gt;&lt;BR /&gt;/*Send Mail using microsoft graph*/&lt;BR /&gt;&lt;SPAN&gt;/* Define the necessary variables */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let graph_api_url=&lt;/SPAN&gt;&lt;A href="https://graph.microsoft.com/v1.0;" target="_blank" rel="noopener"&gt;https://graph.microsoft.com/v1.0;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;%let client_secret=x9y8Q~lA0p5BG~mYdqwDM7FE~ImZIIV5cL9T3cyJ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;/* Define the email message */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let recipient_email=&lt;/SPAN&gt;&lt;A href="mailto:shivrajpawar49@gmail.com" target="_blank" rel="noopener"&gt;shivrajpawar49@gmail.com&lt;/A&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let subject=API SAS;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let message_body=How you doinn??;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;/* Build the JSON payload for the email */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let email_payload={&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"message": {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"subject": "&amp;amp;subject.",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"body": {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"contentType": "Text",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"content": "&amp;amp;message_body."&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"toRecipients": [&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"emailAddress": {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"address": "&amp;amp;recipient_email."&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;};&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;/* Make an HTTP POST request to send the email */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename response TEMP;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename request TEMP;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;data &lt;/SPAN&gt;&lt;I&gt;null&lt;/I&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file request;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put "POST &amp;amp;graph_api_url./users/me/sendMail HTTP/1.1";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put "Host: graph.microsoft.com";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put "Content-Type: application/json";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put "Authorization: Bearer &amp;amp;access_token."; /* Use the access token obtained in your SAS code */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put "Content-Length: " length(&amp;amp;email_payload.);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put &amp;amp;email_payload.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;/* Execute the request and capture the response */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename cmd pipe 'curl -k -X POST --data @request --header "Authorization: Bearer &amp;amp;access_token." &amp;amp;graph_api_url./users/me/sendMail';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;data &lt;/SPAN&gt;&lt;I&gt;null&lt;/I&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;infile cmd length=len;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file response;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put input;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;/* Check the response for any errors */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;data &lt;/SPAN&gt;&lt;I&gt;null&lt;/I&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;infile response;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;put &lt;/SPAN&gt;&lt;I&gt;infile&lt;/I&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Sep 2023 05:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/892840#M2000</guid>
      <dc:creator>Rutujak</dc:creator>
      <dc:date>2023-09-06T05:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Iam trying to Send ,read mail thorugh  sas code using Microsoft Graph</title>
      <link>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/892977#M2004</link>
      <description>&lt;P&gt;So what part are you having problems with?&lt;BR /&gt;Since your code includes macros you should set:&lt;/P&gt;
&lt;PRE&gt;options mprint;&lt;/PRE&gt;
&lt;P&gt;before running the macros to capture the code generated by them.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 15:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/892977#M2004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-06T15:49:54Z</dc:date>
    </item>
    <item>
      <title>Now Getting error</title>
      <link>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/894220#M2011</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;ERROR&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{"error":{"code":"OrganizationFromTenantGuidNotFound","message":"The tenant for tenant guid '0e888a36-e21e-42e0-9cd2-bed9a933d9ee' d&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oes not exist.","innerError":{"oAuthEventOperationId":"173eae30-7d2d-47fe-a7c2-89eaea6d822c","oAuthEventcV":"4BaJutuPZOOnZzJRr+gHNg.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1.1.1","errorUrl":"&lt;/SPAN&gt;&lt;A href="https://aka.ms/autherrors#error-InvalidTenant%22,%22requestId%22:%22434b4ffd-4897-4dd0-84db-9b6cfd211a69%22,%22date%22:%222023-09" target="_blank" rel="noopener"&gt;https://aka.ms/autherrors#error-InvalidTenant","requestId":"434b4ffd-4897-4dd0-84db-9b6cfd211a69","date":"2023-09&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;-13T05:16:41"}}}&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;After a Modified Code&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro to process the JSON token&lt;BR /&gt;file that was created at authorization time.&lt;BR /&gt;This will fetch the access token, refresh token,&lt;BR /&gt;and expiration datetime for the token so we know&lt;BR /&gt;if we need to refresh it.&lt;BR /&gt;*/&lt;BR /&gt;%macro process_token_file(file);&lt;BR /&gt;libname oauth json fileref=&amp;amp;file.;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set oauth.root;&lt;BR /&gt;call symputx('access_token', access_token,'G');&lt;BR /&gt;call symputx('refresh_token', refresh_token,'G');&lt;BR /&gt;/* convert epoch value to SAS datetime */&lt;BR /&gt;call symputx('expires_on',(input(expires_on,best32.)+'01jan1970:00:00'dt),'G');&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro that retrieves the initial access token&lt;BR /&gt;by redeeming the authorization code that you're granted&lt;BR /&gt;during the interactive step using a web browser&lt;BR /&gt;while signed into your Microsoft OneDrive / Azure account.&lt;/P&gt;&lt;P&gt;This step also creates the initial token.json that will be&lt;BR /&gt;used on subsequent steps/sessions to redeem a refresh token.&lt;BR /&gt;*/&lt;BR /&gt;%macro get_token(client_id,&lt;BR /&gt;client_secret,&lt;BR /&gt;code,&lt;BR /&gt;scope,&lt;BR /&gt;outfile,&lt;BR /&gt;redirect_uri=&lt;A href="https://deployopt.demo.com/SASLogon/login/callback/azure" target="_blank"&gt;https://deployopt.demo.com/SASLogon/login/callback/azure&lt;/A&gt;,&lt;BR /&gt;tenant=0e888a36-e21e-42e0-9cd2-bed9a933d9ee,&lt;BR /&gt;debug=0);&lt;/P&gt;&lt;P&gt;proc http url="&lt;A href="https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token" target="_blank"&gt;https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token&lt;/A&gt;"&lt;BR /&gt;method="POST"&lt;BR /&gt;in="%nrstr(&amp;amp;client_id)=&amp;amp;client_id.%nrstr(&amp;amp;client_secret)=&amp;amp;client_secret.%nrstr(&amp;amp;code)=&amp;amp;code.%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri%nrstr(&amp;amp;grant_type)=authorization_code%nrstr(&amp;amp;scope)=&amp;amp;scope."&lt;BR /&gt;out=&amp;amp;outfile.;&lt;BR /&gt;%if &amp;amp;debug&amp;gt;=0 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;debug.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if &amp;amp;_DEBUG_. ge 1 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;_DEBUG_.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%process_token_file(&amp;amp;outfile);&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Utility macro to redeem the refresh token&lt;BR /&gt;and get a new access token for use in subsequent&lt;BR /&gt;calls to the OneDrive service.&lt;BR /&gt;*/&lt;BR /&gt;%macro refresh(client_id,&lt;BR /&gt;client_secret,&lt;BR /&gt;refresh_token,&lt;BR /&gt;scope,&lt;BR /&gt;outfile,&lt;BR /&gt;redirect_uri=&lt;A href="https://deployopt.demo.com/SASLogon/login/callback/azure" target="_blank"&gt;https://deployopt.demo.com/SASLogon/login/callback/azure&lt;/A&gt;,&lt;BR /&gt;tenant=common,&lt;BR /&gt;debug=0);&lt;/P&gt;&lt;P&gt;proc http url="&lt;A href="https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token" target="_blank"&gt;https://login.microsoftonline.com/0e888a36-e21e-42e0-9cd2-bed9a933d9ee/oauth2/v2.0/token&lt;/A&gt;"&lt;BR /&gt;method="POST"&lt;BR /&gt;in="%nrstr(&amp;amp;client_id)=&amp;amp;client_id.%nrstr(&amp;amp;client_secret)=&amp;amp;client_secret.%nrstr(&amp;amp;refresh_token=)&amp;amp;refresh_token%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;grant_type)=refresh_token%nrstr(&amp;amp;scope)=&amp;amp;scope."&lt;BR /&gt;out=&amp;amp;outfile.;&lt;BR /&gt;%if &amp;amp;debug. ge 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;debug.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %symexist(_DEBUG_) AND &amp;amp;_DEBUG_. ge 1 %then&lt;BR /&gt;%do;&lt;BR /&gt;debug level=&amp;amp;_DEBUG_.;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%process_token_file(&amp;amp;outfile);&lt;BR /&gt;%mend refresh;&lt;BR /&gt;&lt;BR /&gt;/* generate Token */&lt;/P&gt;&lt;DIV&gt;%let config_root=/sasdata;&lt;/DIV&gt;&lt;DIV&gt;%if %symexist(config_root) %then %do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; filename config "&amp;amp;config_root./config.json";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; libname config json fileref=config;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; data _null_;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;set config.root;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('tenant_id',tenant_id,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('client_id',client_id,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('redirect_uri',redirect_uri,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('client_secret',client_secret,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;call symputx('scope',scope,'G');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; run;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;%else %do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; %put ERROR: You must define the CONFIG_ROOT macro variable.;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%let authorize_url=&lt;A href="https://login.microsoftonline.com/&amp;amp;tenant_id./oauth2/v2.0/authorize?client_id=&amp;amp;client_id.%nrstr(&amp;amp;response_type)=code%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;scope)=&amp;amp;scope" target="_blank"&gt;https://login.microsoftonline.com/&amp;amp;tenant_id./oauth2/v2.0/authorize?client_id=&amp;amp;client_id.%nrstr(&amp;amp;response_type)=code%nrstr(&amp;amp;redirect_uri)=&amp;amp;redirect_uri.%nrstr(&amp;amp;scope)=&amp;amp;scope&lt;/A&gt;.;&lt;/DIV&gt;&lt;DIV&gt;options nosource;&lt;/DIV&gt;&lt;DIV&gt;%put Paste this URL into your web browser:;&lt;/DIV&gt;&lt;DIV&gt;%put -- START -------;&lt;/DIV&gt;&lt;DIV&gt;%put &amp;amp;authorize_url;&lt;/DIV&gt;&lt;DIV&gt;%put ---END ---------;&lt;/DIV&gt;&lt;DIV&gt;options source;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename token "&amp;amp;config_root./token.json";&lt;/DIV&gt;&lt;DIV&gt;%let auth_code=0.ASsANoqIDh7i4EKc0r7ZqTPZ7jwymLltqM1Ao9E-7URpiinCAAA.AgABAAIAAAAtyolDObpQQ5VtlI4uGjEPAgDs_wUA9P-O2Dj3uaJl1brAZnNrFCJl0Hbmyd-N3gb2ToMjb4L5Xd8LSegqzaKJ1hajRaRrCmvxtFsBeNe-ukY7q8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ad3VtFx1Ar6M23jzdDQTS1klDtVd48ai0JaTd6vclYR_M-CFnqn3oGkHYLC2aLUCn9Wmg4_1juireRu2WxSW7Z1f4E1CtXWTEC0cY58g5osocbVl57yw;&lt;/DIV&gt;&lt;DIV&gt;/*&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; Now that we have an authorization code we can get the access token&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; This step will write the tokens.json file that we can use in our&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; production programs.&lt;/DIV&gt;&lt;DIV&gt;*/&lt;/DIV&gt;&lt;DIV&gt;%get_token(&amp;amp;client_id.,&amp;amp;client_secret.,&amp;amp;auth_code,&amp;amp;scope.,token,tenant=&amp;amp;tenant_id);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename token "&amp;amp;config_root./token.json";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%process_token_file(token);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* If this is first use for the session, we'll likely need to refresh&amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;/* the token.&amp;nbsp; This will also call process_token_file again and update */&lt;/DIV&gt;&lt;DIV&gt;/* our token.json file.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;%refresh(&amp;amp;client_id.,&amp;amp;refresh_token.,&amp;amp;resource.,token,tenant=&amp;amp;tenant_id.);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;filename resp TEMP;&lt;/DIV&gt;&lt;DIV&gt;/* Note: oauth_bearer option added in 9.4M5 */&lt;/DIV&gt;&lt;DIV&gt;proc http url="&lt;A href="https://graph.microsoft.com/v1.0/me/sendMail" target="_blank"&gt;https://graph.microsoft.com/v1.0/me/sendMail&lt;/A&gt;"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;oauth_bearer="&amp;amp;access_token"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;out = resp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;libname jresp json fileref=resp;&lt;BR /&gt;&lt;BR /&gt;/* send MAil*/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;%let EMAIL_ADDRESS = shivraj.pawar@woodpeckerind.com;&lt;BR /&gt;filename send temp;&lt;BR /&gt;data null;&lt;BR /&gt;file send;&lt;BR /&gt;put '{"message": {'&lt;BR /&gt;'"subject": "Test Email",'&lt;BR /&gt;'"body": {'&lt;BR /&gt;'"contentType": "Text",'&lt;BR /&gt;'"content": "This is a test email."'&lt;BR /&gt;'},'&lt;BR /&gt;'"toRecipients": ['&lt;BR /&gt;'{'&lt;BR /&gt;'"emailAddress": {'&lt;BR /&gt;'"address": "' "&amp;amp;EMAIL_ADDRESS." '"'&lt;BR /&gt;'}'&lt;BR /&gt;'}'&lt;BR /&gt;']'&lt;BR /&gt;'}}';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;filename resp temp;&lt;BR /&gt;proc http&lt;BR /&gt;method="POST"&lt;BR /&gt;url="&lt;A href="https://graph.microsoft.com/v1.0/me/sendMail" target="_blank"&gt;https://graph.microsoft.com/v1.0/me/sendMail&lt;/A&gt;"&lt;BR /&gt;in=send&lt;BR /&gt;out=resp; /* Store the response in a file */&lt;BR /&gt;headers "Content-Type"="application/json"&lt;BR /&gt;"Authorization"="Bearer &amp;amp;access_token.";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Check the response for success or error */&lt;BR /&gt;data _null_;&lt;BR /&gt;infile resp;&lt;BR /&gt;input;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 06:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/Iam-trying-to-Send-read-mail-thorugh-sas-code-using-Microsoft/m-p/894220#M2011</guid>
      <dc:creator>Rutujak</dc:creator>
      <dc:date>2023-09-14T06:20:01Z</dc:date>
    </item>
  </channel>
</rss>

