Authorization Denied - Sending Email Through Analysis

Authorization Denied - Sending Email Through Analysis

For some reason I cannot send an email through analysis. Here is my code where I create a user and then want to send them a welcome email. I have an access policy where this analysis is allowed to send emails but I still get authorization denied. 

Any advise?

      await resources.run.userCreate(data);
      context.log(`User created with email: ${email}`);

    // Sending an email to the new user
      const services = new Services({ token: environment.accountToken });
      await services.email.send({
        to: email,
        subject: "Welcome",
        message: `Hello ${name},Welcome to our portal!,
      });

      context.log("Email sent to the new user successfully.");
    } catch (error) {
      context.log(`Failed to create user or send email: ${error}`);
    }
  }
}