# Using sendGrid send multiple files

**URL:** <https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [August 28, 2020, 6:02am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780 "2020-08-28T06:02:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanami](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nanami/32/1875_2.png) [@nanami](https://forum.wixstudio.com/u/nanami)\
**Post date:** [August 28, 2020, 6:02am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/1 "2020-08-28T06:02:10Z")

</div>

I checked this forum  
[https://www.wix.com/corvid/forum/community-discussion/include-images-documents-in-form-submission-email](https://www.wix.com/corvid/forum/community-discussion/include-images-documents-in-form-submission-email)

It’s works.  
But when only 1 image sends, it does not work.

Please help me.

```javascript
import {sendEmail} from 'backend/email';

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

// wix:document://v1 -> docs.wixstatic.com/ugd

function sendFormData() {
try{

 
 const item = $w("#dataset1").getCurrentItem();
 const wiximageurl = "https://static.wixstatic.com/media/";
 let imagelocal = "";
      imagelocal = item.image.replace('image://v1/', '');
      imagelocal = imagelocal.substr(imagelocal.lastIndexOf('/')+1);
 const imageUrl = wiximageurl + imagelocal;

 let whoimagelocal = "";
     whoimagelocal = item.whoimage.replace('image://v1/', '');
      whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf('/')+1);
 const whoimageUrl = wiximageurl + whoimagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
    \name: ${$w("#input1").value}
    \mail: ${$w("#input2").value}
    \birthday: ${$w("#datePicker1").value}
    \image: ${imageUrl}

    \onother: ${$w("#checkbox1").value}
    \name2: ${$w("#input3").value}
    \relationship: ${$w("#input4").value}
    \birthday2: ${$w("#datePicker2").value}
    \image2: ${whoimageUrl}

    \comment: ${$w("#richTextBox1").value}
        `;

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

}catch(e){
 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
    \name: ${$w("#input1").value}
    \mail: ${$w("#input2").value}
    \birthday: ${$w("#datePicker1").value}
 

    \onother: ${$w("#checkbox1").value}
    \name2: ${$w("#input3").value}
    \relationship: ${$w("#input4").value}
    \birthday2: ${$w("#datePicker2").value}

    \comment: ${$w("#richTextBox1").value}
        `;

 
 

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

```

---

<div class="post-metadata">

**Author:** ![nanami](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nanami/32/1875_2.png) [@nanami](https://forum.wixstudio.com/u/nanami)\
**Post date:** [August 29, 2020, 10:07am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/2 "2020-08-29T10:07:24Z")

</div>

someone help me

---

<div class="post-metadata">

**Author:** ![nanami](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nanami/32/1875_2.png) [@nanami](https://forum.wixstudio.com/u/nanami)\
**Post date:** [August 31, 2020, 3:14am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/3 "2020-08-31T03:14:22Z")

</div>

anyone help me

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [August 31, 2020, 3:28am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/4 "2020-08-31T03:28:54Z")

</div>

I think the simplest solution here will be to use if/else

```javascript
try{
 const item = $w("#dataset1").getCurrentItem();
 const wiximageurl = "https://static.wixstatic.com/media/";
 let imagelocal = "";
 if(item.image && item.whoimage) {
            imagelocal = item.image.replace('image://v1/', '');
            imagelocal = imagelocal.substr(imagelocal.lastIndexOf('/')+1);
 const imageUrl = wiximageurl + imagelocal;

 let whoimagelocal = "";
            whoimagelocal = item.whoimage.replace('image://v1/', '');
            whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf('/')+1);
 const whoimageUrl = wiximageurl + whoimagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
            \name: ${$w("#input1").value}
            \mail: ${$w("#input2").value}
            \birthday: ${$w("#datePicker1").value}
            \image: ${imageUrl}

            \onother: ${$w("#checkbox1").value}
            \name2: ${$w("#input3").value}
            \relationship: ${$w("#input4").value}
            \birthday2: ${$w("#datePicker2").value}
            \image2: ${whoimageUrl}

            \comment: ${$w("#richTextBox1").value}`;

            sendEmail(subject, body)
            .then(response => console.log(response));
        } else if(item.image && !item.whoimage) {
            imagelocal = item.image.replace('image://v1/', '');
            imagelocal = imagelocal.substr(imagelocal.lastIndexOf('/')+1);
 const imageUrl = wiximageurl + imagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
            \name: ${$w("#input1").value}
            \mail: ${$w("#input2").value}
            \birthday: ${$w("#datePicker1").value}
            \image: ${imageUrl}

            \onother: ${$w("#checkbox1").value}
            \name2: ${$w("#input3").value}
            \relationship: ${$w("#input4").value}
            \birthday2: ${$w("#datePicker2").value}

            \comment: ${$w("#richTextBox1").value}`;

            sendEmail(subject, body)
            .then(response => console.log(response));
        } else if(!item.image && item.whoimage) {
 let whoimagelocal = "";
            whoimagelocal = item.whoimage.replace('image://v1/', '');
            whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf('/')+1);
 const whoimageUrl = wiximageurl + whoimagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
            \name: ${$w("#input1").value}
            \mail: ${$w("#input2").value}
            \birthday: ${$w("#datePicker1").value}

            \onother: ${$w("#checkbox1").value}
            \name2: ${$w("#input3").value}
            \relationship: ${$w("#input4").value}
            \birthday2: ${$w("#datePicker2").value}
            \image2: ${whoimageUrl}

            \comment: ${$w("#richTextBox1").value}`;

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

```

---

<div class="post-metadata">

**Author:** ![nanami](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nanami/32/1875_2.png) [@nanami](https://forum.wixstudio.com/u/nanami)\
**Post date:** [August 31, 2020, 6:19am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/5 "2020-08-31T06:19:17Z")

</div>

Hi shan,  
Thank you for your replay.  
but it’s not work.

This errs

 ![](https://us1.discourse-cdn.com/wix/original/3X/3/2/322ef60183741faa99ca28089e2fa0ecc9704a58.png)

 Error parsing web-module 'public/pages/vxzvz.js': Missing catch or finally clause (35:0) while parsing file: public/pages/vxzvz.js 

I wrote this code:

```javascript
try{
 const item = $w("#dataset1").getCurrentItem();
 const wiximageurl = "https://static.wixstatic.com/media/";
 let imagelocal = "";
 if(item.image && item.whoimage) {
            imagelocal = item.image.replace('image://v1/', '');
            imagelocal = imagelocal.substr(imagelocal.lastIndexOf('/')+1);
 const imageUrl = wiximageurl + imagelocal;

 let whoimagelocal = "";
            whoimagelocal = item.whoimage.replace('image://v1/', '');
            whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf('/')+1);
 const whoimageUrl = wiximageurl + whoimagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
            \name: ${$w("#input1").value}
            \mail: ${$w("#input2").value}
            \birthday: ${$w("#datePicker1").value}
            \image: ${imageUrl}

            \onother: ${$w("#checkbox1").value}
            \name2: ${$w("#input3").value}
            \relationship: ${$w("#input4").value}
            \birthday2: ${$w("#datePicker2").value}
            \image2: ${whoimageUrl}

            \comment: ${$w("#richTextBox1").value}`;

            sendEmail(subject, body)
            .then(response => console.log(response));
        } else if(item.image && !item.whoimage) {
            imagelocal = item.image.replace('image://v1/', '');
            imagelocal = imagelocal.substr(imagelocal.lastIndexOf('/')+1);
 const imageUrl = wiximageurl + imagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
            \name: ${$w("#input1").value}
            \mail: ${$w("#input2").value}
            \birthday: ${$w("#datePicker1").value}
            \image: ${imageUrl}

            \onother: ${$w("#checkbox1").value}
            \name2: ${$w("#input3").value}
            \relationship: ${$w("#input4").value}
            \birthday2: ${$w("#datePicker2").value}

            \comment: ${$w("#richTextBox1").value}`;

            sendEmail(subject, body)
            .then(response => console.log(response));
        } else if(!item.image && item.whoimage) {
 let whoimagelocal = "";
            whoimagelocal = item.whoimage.replace('image://v1/', '');
            whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf('/')+1);
 const whoimageUrl = wiximageurl + whoimagelocal;

 const subject = `From website： ${$w("#input1").value}`;
 const body = `plan: ${$w("#dropdown1").value}
            \name: ${$w("#input1").value}
            \mail: ${$w("#input2").value}
            \birthday: ${$w("#datePicker1").value}

            \onother: ${$w("#checkbox1").value}
            \name2: ${$w("#input3").value}
            \relationship: ${$w("#input4").value}
            \birthday2: ${$w("#datePicker2").value}
            \image2: ${whoimageUrl}

            \comment: ${$w("#richTextBox1").value}`;

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

```

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [August 31, 2020, 6:40am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/6 "2020-08-31T06:40:06Z")

</div>

@nanami You should have only replaced the code inside try and left the catch() statement where it was

---

<div class="post-metadata">

**Author:** ![nanami](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nanami/32/1875_2.png) [@nanami](https://forum.wixstudio.com/u/nanami)\
**Post date:** [August 31, 2020, 8:10am UTC](https://forum.wixstudio.com/t/using-sendgrid-send-multiple-files/39780/7 "2020-08-31T08:10:51Z")

</div>

@shantanukumar847 Amazing!!! it’s work!!! thank you so much.  
I wrote all codes for the same case.

import {sendEmail} from ‘backend/email’;

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

// wix:document://v1 → [docs.wixstatic.com/ugd](http://docs.wixstatic.com/ugd)

function sendFormData() {  
**try** {

const item = $w(“#dataset1”).getCurrentItem();  
const wiximageurl = “[https://static.wixstatic.com/media/](https://static.wixstatic.com/media/)”;  
let imagelocal = “”;

**if(item.image && item.whoimage** ) {

imagelocal = item.image.replace(‘image://v1/’, ‘’);  
imagelocal = imagelocal.substr(imagelocal.lastIndexOf(‘/’)+1);  
const imageUrl = wiximageurl + imagelocal;

let whoimagelocal = “”;  
whoimagelocal = item.whoimage.replace(‘image://v1/’, ‘’);  
whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf(‘/’)+1);  
const whoimageUrl = wiximageurl + whoimagelocal;

const subject = `From website： ${$w("#input1").value}`;  
const body = `plan: ${$w(“#dropdown1”).value}  
\name: ${$w(“#input1”).value}  
\mail: ${$w(“#input2”).value}  
\birthday: ${$w(“#datePicker1”).value}  
\image: ${imageUrl}

\onother: ${$w(“#checkbox1”).value}  
\name2: ${$w(“#input3”).value}  
\relationship: ${$w(“#input4”).value}  
\birthday2: ${$w(“#datePicker2”).value}  
\image2: ${whoimageUrl}

\comment: ${$w(“#richTextBox1”).value}  
`;

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

} **else if(item.image && !item.whoimage** ) {  
imagelocal = item.image.replace(‘image://v1/’, ‘’);  
imagelocal = imagelocal.substr(imagelocal.lastIndexOf(‘/’)+1);  
const imageUrl = wiximageurl + imagelocal;

const subject = `From website： ${$w("#input1").value}`;  
const body = `plan: ${$w(“#dropdown1”).value}  
\name: ${$w(“#input1”).value}  
\mail: ${$w(“#input2”).value}  
\birthday: ${$w(“#datePicker1”).value}  
\image: ${imageUrl}

\onother: ${$w(“#checkbox1”).value}  
\name2: ${$w(“#input3”).value}  
\relationship: ${$w(“#input4”).value}  
\birthday2: ${$w(“#datePicker2”).value}

\comment: ${$w(“#richTextBox1”).value}`;

sendEmail(subject, body)  
.then(response =\> console.log(response));  
} **else if(!item.image && item.whoimage** ) {  
let whoimagelocal = “”;  
whoimagelocal = item.whoimage.replace(‘image://v1/’, ‘’);  
whoimagelocal = whoimagelocal.substr(whoimagelocal.lastIndexOf(‘/’)+1);  
const whoimageUrl = wiximageurl + whoimagelocal;

const subject = `From website： ${$w("#input1").value}`;  
const body = `plan: ${$w(“#dropdown1”).value}  
\name: ${$w(“#input1”).value}  
\mail: ${$w(“#input2”).value}  
\birthday: ${$w(“#datePicker1”).value}

\onother: ${$w(“#checkbox1”).value}  
\name2: ${$w(“#input3”).value}  
\relationship: ${$w(“#input4”).value}  
\birthday2: ${$w(“#datePicker2”).value}  
\image2: ${whoimageUrl}

\comment: ${$w(“#richTextBox1”).value}`;

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

} catch (e){  
const subject = `From website： ${$w("#input1").value}`;  
const body = `plan: ${$w(“#dropdown1”).value}  
\name: ${$w(“#input1”).value}  
\mail: ${$w(“#input2”).value}  
\birthday: ${$w(“#datePicker1”).value}

\onother: ${$w(“#checkbox1”).value}  
\name2: ${$w(“#input3”).value}  
\relationship: ${$w(“#input4”).value}  
\birthday2: ${$w(“#datePicker2”).value}

\comment: ${$w(“#richTextBox1”).value}  
`;

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