I got an email program from sendgrid.com.
https://www.vorbly.com/Vorbly-Code/WIX-SENDGRID-API-V3—AUTO-EMAIL-MESSAGES
After running, the following prompt appears.
I am not very clear about what kind of error this is and how it should be corrected. Hope help.
The following are elements and code at page
the following are code in Backend.
sendGrid.js
import { fetch } from ‘wix-fetch’ ;
export function sendWithService ( key , sender , recipient , subject , body , date ) {
const url = “https://api.sendgrid.com/v3/mail/send” ;
const headers = {
“Authorization” : "Bearer " + key ,
“Content-Type” : “application/json”
};
const data = {
"personalizations" : [{
"to" : [{
"email" : recipient
}]
}],
"from" : {
"email" : sender
},
"subject" : subject ,
"content" : [{
"type" : "text/html" ,
"value" : body
}]
};
return fetch ( url , {
"method" : "POST" ,
"headers" : headers ,
"body" : JSON . stringify ( data )
})
. then ( response => response . text );
}
email.jsw
import { sendWithService } from ‘backend/sendGrid’ ;
export function sendEmail ( subject , body ) {
const key = “SG._HbV2s-ASU-3qed3_Bz6-Q.uQR2Fa2cOVAVRX20BGtpl57f76eO1LGiDrGR8whz8” ; // Replace with your API key //
const sender = “laizhihong88@gmail.com” ; // Sender email //
const recipient = “jacklai88@yahoo.com” ; // Notification to yourself //
return sendWithService ( key , sender , recipient , subject , body );
}
export function sendEmailWithRecipient ( subject , body , recipient ) {
const key = “SG._HbV2s-ASU-3qed3_Bz6-Q.uQR2Fa2cOVAVRX20BGtpl57f76eO1LGiDrGR8whz8” ; // Replace with your API key //
const sender = “laizhihong88@gmail.com” ; // Sender email //
return sendWithService ( key , sender , recipient , subject , body ); // Customer email //
}