# Database email notification 

**URL:** <https://forum.wixstudio.com/t/database-email-notification/12184>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [February 6, 2019, 5:22pm UTC](https://forum.wixstudio.com/t/database-email-notification/12184 "2019-02-06T17:22:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron-strickland](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/aaron-strickland/32/8945_2.png) [@aaron-strickland](https://forum.wixstudio.com/u/aaron-strickland)\
**Post date:** [February 6, 2019, 5:22pm UTC](https://forum.wixstudio.com/t/database-email-notification/12184/1 "2019-02-06T17:22:18Z")

</div>

i’m getting recipient not defined yet i believe it has been done correctly I marked the issue in italic and underlined 13 lines down

import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;

$w.onReady( function () {  
$w(“#dataset1”).onAfterSave(sendFormData);  
});

function sendFormData() {  
const subject = `New Employee Application ${$w("#input1").value}`;  
const body = `Type Here: ${$w("#input1").value} \rName: ${$w("#input1").value} \rPhone: ${$w("#input2").value} \rLocation: ${$w("#input3").value} \rJobSkills&Training: ${$w("#textBox1").value} \rResume: ${$w("#uploadButton1").value}`;

sendEmailWithRecipient(subject, body, _recipient_ )  
.then(response =\> console.log(response));

sendEmail(subject, body)  
.then(response =\> console.log(response));  
}

import {sendWithService} from ‘backend/sendGrid’;

export function sendEmail(subject, body) {  
const key = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;  
const sender = “mr-trim@live.ca”;  
const recipient = “mr-trim@live.ca”;  
**return** sendWithService(key, sender, recipient, subject, body);  
}

export function sendEmailWithRecipient(subject, body, recipient) {  
const key = “SG.Nntl\_VUlSgWXBTQaLPZ8Ww.-\_7BOPzBM6IN2ZJVrXFEJ-pRbewrzsCWd5bfTLl–m8”;  
const sender = “mr-trim@live.ca”;  
**return** sendWithService(key, sender, recipient, subject, body);  
}

.js File: sendGrid.js

[//sendGrid.js](https://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](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());

---

<div class="post-metadata">

**Author:** ![brettfranklin2](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/brettfranklin2/32/3944_2.png) [@brettfranklin2](https://forum.wixstudio.com/u/brettfranklin2)\
**Post date:** [February 7, 2019, 3:57am UTC](https://forum.wixstudio.com/t/database-email-notification/12184/2 "2019-02-07T03:57:58Z")

</div>

Try using the Automations feature.

---

<div class="post-metadata">

**Author:** ![aaron-strickland](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/aaron-strickland/32/8945_2.png) [@aaron-strickland](https://forum.wixstudio.com/u/aaron-strickland)\
**Post date:** [February 7, 2019, 3:12pm UTC](https://forum.wixstudio.com/t/database-email-notification/12184/3 "2019-02-07T15:12:15Z")

</div>

thanks that worked great and was much faster.
