Is there a way to get a mail sent when new data is loaded into a database?
I want to use the database for a guestbook.
And with a new entry I would like a notification.
Greetings Ronny
PS: Sorry if the English is bad, I work with Google translator.
Hi,
of course! There is an article describing just that here:
Let me know if you need any further assistance. And have fun Wix Coding!
Many thanks for the answer.
But, how can I create a backend file?
I tried to follow the directions from A wix expert and could not get it to work. Is anyone else having that problem?
UPDATE: Remember to check your SPAM folder!!! The U-tube video I followed from the expert was PERFECT… it was the “operator” (me) who made the error by not checking the other folders. Thanks Wix Experts!
Unfortunately, I still have not got any further.
To create a backend file click on “+” icon next to Backend folder:
OK thanks
But it does not work.
No idea where I still have mistakes.
I created a sendGrid account.
There I have created an API key.
Then I created a backend web module named “email.jsw”.
There is reasoning in it:
//email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "Here is the created API code";
const sender = "dj-ronny.net@wix-domains.com";
const recipient = "info@dj-ronny.net";
return sendWithService(key, sender, recipient, subject, body);
}
Then I created a new “.js-file” called “sendGrid.js”.
There is the following in there:
//sendGrid.js
import {fetch} from 'wix-fetch';
export function sendWithService(key, sender, recipient, subject, body) {
const url = "https://api.sendgrid.com/api/mail.send.json";
const headers = {
"Authorization": "Bearer " + key,
"Content-Type": "application/x-www-form-urlencoded"
};
const data = `from=${sender}&to=${recipient}&subject=${subject}&text=${body}`;
const request = {
"method": "post",
"headers": headers,
"body": data
};
return fetch(url, request)
.then(response => response.json());
}
Then I entered the following on the page for the guestbook entries in the code for the page:
import {sendEmail} from 'backend/email';
$w.onReady(function () {
$w("#Gaestebuch dataset").onAfterSave(sendFormData);
});
function sendFormData() {
const subject = `New Submission from ${$w("#input1").value}`;
const body = `Ihr Name: ${$w("#input1").value}
\rComments: ${$w("#textBox1").value}`;
sendEmail(subject, body)
.then(response => console.log(response));
}
Hi Ronald,
My guess is this line:
$w("#Gaestebuch dataset").onAfterSave(sendFormData); // it's not possible to leave a space in the id name of an element.
Please update in your progress.
Roi
Hello Roi,
Many thanks for your response.
I changed the line.
$w("#dataset1").onAfterSave(sendFormData);

Unfortunately it still does not work.
I’m also not sure if this line in sendGrid.js is correct.
"Authorization": "Bearer " + key,
According to the instructions, nothing should be changed there.
In my developer console after sending me the following error appears:
Wix code SDK error: The "src" property cannot be set to "". It must be a valid URL starting with "http://", "https://", or "image://".
Hi,
Can you please share a link to your site so we can inspect ?
Roi
I just can not manage it. : - /
Is not there a solution that works?
Hi,
The code looks ok regarding sending email.
Did you check the spam folder ?
You receive that warning because the image in the repeater is connected to an empty field.
Roi
Hello Roi,
many, many thanks for your tip.
That was the rustling solution.
The mails have actually landed in the Spam folder without a message for me to display.
Great. It works! 
Thank you very much
Glad to hear it worked!
Roi