13,721 questions
NodeJs Graph sendMail
Ruben Teevin
11
Reputation points
I'm trying to implement a function to send Emails using the graph API.
require('isomorphic-fetch');
const { Client } = require('@microsoft/microsoft-graph-client');
const { TokenCredentialAuthenticationProvider } = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials');
const { ClientSecretCredential } = require('@azure/identity');
const tenantId = 'xx';
const clientId = 'xx';
const clientSecret = 'xx';
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['https://graph.microsoft.com/.default']
});
const client = Client.initWithMiddleware({
debugLogging: true,
authProvider
});
I tried sending "invitations" and it works
client.api('/invitations').post(invitation)
But for sending emails
client.api('/users/<My-User-Principal-Name>/sendMail')
when<My-User-Principal-Name> is my email Im getting this error
{"code":"Request_BadRequest","message":"Specified HTTP method is not allowed for the request target."...}
and when its my ID, I get this
{"error":{"code":"OrganizationFromTenantGuidNotFound","message":"The tenant for tenant guid..."}}
Help please :)
Microsoft Security Microsoft Graph
Sign in to answer