Emailjs error need help with

Hi guys and mainly @giri-zano

Im desperate to get away from send grid due to undelivered mails to Hotmail due to some kind of black list or firewall.

I found the old post from @giri-zano i couldn’t reply as its closed.

https://www.wix.com/velo/forum/coding-with-velo/how-to-design-my-email-notification

I followed the code here however i get a error on send email

returns this error from JSW “Oops… API calls are disabled for non-browser applications” what does that mean? how do i fix it?

 .catch((error) => {

            console.log('Oops... ' + error);

 });
 }

//email_meal_plan_questionnaire.jsw

import {fetch} from 'wix-fetch';

export function sendEmail(emailprovider, template, params) {

 const userid = "user_my id"; // put your emailjs userid here (look in Account)

 const url = "https://api.emailjs.com/api/v1.0/email/send";

// if no email provider specified, then use this one

 if (!emailprovider) {

        emailprovider="service_xxx";

 }

// if no email template specified, then use this one

 if (!template) {

        template="meal_plan_questionnaire";

 }

 

 let full_params = {

 "user_id": userid,

 "service_id": emailprovider,

 "template_id": template,

 "template_params": params

 };

 const headers = {

 "Content-type": "application/json"

 };

 const request = {

        method: 'POST',

        headers: headers,

        body: JSON.stringify(full_params)

 };

 return fetch(url, request)

 .then((httpResponse) => {

 if (httpResponse.ok) {

                console.log('Your mail is sent!');

 } else {

 return httpResponse.text()

 .then(text => Promise.reject(text));

 }

 })

 .catch((error) => {

            console.log('Oops... ' + error);

 });
 }

My submit button code

import {sendEmail} from 'backend/email_meal_plan_questionnaire';
 
 let myprovider = "service_xxxx"; //use her the alias you used for this service in emailJS
 let mytemplate = "meal_plan_questionnaire"; //use her the template name you defined in emailJS
 let myparams = {

 "first_name": $w('#firstNametextbox').value,
 "last_name":  $w('#lastNametextbox').value,
 "dob": $w('#DOBdatePicker').value,
 "weight": $w('#weightTextbox').value,
 "email_address": $w('#emailAddresstextbox').value,

 };

            sendEmail (myprovider, mytemplate, myparams);
 }

Many thanks

Dan

emailjs recently beefed up their security. You must check “Allow EmailJS API for non-browser applications.” and if using access token, the second too. In that case, store access token in Wix Secrets and retrieve it with backend function. And don’t propagate token to frontend.
All of this is done in your account setting on emailjs.

Thanks @giri-zano

I emailed Emailjs aswell they replied with the same very prompt reply.

Does the attachment function work ok ? id like the email to be sent out with 4 photos that my client uploads to the form is that possible?

Regards

Dan

@krays23 I believe attachments are only possible with the paid level, but you will have to check with emailjs.