how send a email in react native with emailjs

I created a react native app with expo, I have emailjs. this option are enabled

enter image description here

but I have the next error when I send the form.

FAILED... {"status": 403, "text": "API calls in strict mode, but no private key was passed"}

this is my code, can any help me?? where I put it and how do I pass the private key?...

import emailjs from '@emailjs/browser';

import {
  serviceID,
  templateID,
  publicKey,
  emailUserid,
  accessToken,
} from '../../utils/email-configuration';


export const emailSend = (data) => {
  let templateParams = {
    to_name: `${values.name}`,
    to_email: `${values.email}`,
    from_name: 'Juan',
    message: `${values.description}`,
  };
  console.log('ENVIADOS: ', JSON.stringify(templateParams));

  emailjs.send(serviceID, templateID, templateParams, publicKey).then(
    function (response) {
      console.log('SUCCESS!', response.status, response.text);
    },
    function (error) {
      console.log('FAILED...', error);
    }
  );
};

I try in the field of public key send a json with public and private key.

const Options = {
   publicKey: publicKey,
   accessToken: privateKey,
  };
 

emailjs.send(serviceID, templateID, templateParams, Options)

Upvotes: 4

Views: 1844

Answers (2)

fadingbeat
fadingbeat

Reputation: 433

You should pass a private key in the same way you pass public key, service template and service id:

var data = {
    service_id: 'YOUR_SERVICE_ID',
    template_id: 'YOUR_TEMPLATE_ID',
    user_id: 'YOUR_PUBLIC_KEY',
    accessToken: 'YOUR_ACCESS_TOKEN',
    template_params: {
        'username': 'James',
        'g-recaptcha-response': '03AHJ_ASjnLA214KSNKFJAK12sfKASfehbmfd...'
    }
};

Documentation: https://www.emailjs.com/docs/rest-api/send/

Here's an article I wrote explaining how to setup sensitive EmailJS data in Vite+React app deployed on Vercel.

https://medium.com/@fadingbeat/securely-sending-emails-with-emailjs-in-a-vite-react-app-on-vercel-5b8a591fd121

Upvotes: 0

Paul Chesa
Paul Chesa

Reputation: 66

I had the same problem.

Step 1

Go to this page: https://dashboard.emailjs.com/admin/account/security

Step 2

On the page: https://dashboard.emailjs.com/admin/account/security, Change the API settings. Uncheck the box of use private keys: setting to change. view here.

Upvotes: 5

Related Questions