1

My Code.gs file in my apps script project has this code (given below) whose task is to send an email using AWS SES Javascript SDK. -

function doGet() {
    var self=globalThis;
    var url = "https://sdk.amazonaws.com/js/aws-sdk-2.1206.0.min.js";
    eval(UrlFetchApp.fetch(url).getContentText());

        const data1 = "[email protected] | John Doe";
        const data = data1.split(" | ");
        const email = data[0];
        const name = data[1];
        
        const configure = {
            accessKeyId: "<mykeyid>",
            secretAccessKey: "<mykeysecret>",
            apiVersion: '2010-12-01',
            region: 'us-east-1'
        };
        
        const ses = new AWS.SES(configure);
        const parameters = {
            Destination:{
                ToAddresses:[
                    email
                ]
            },
            Message: {
                Body: {
                    Html: {
                        Charset: "UTF-8",
                        Data: `<!DOCTYPE html><html>Hi, ` + name + `!</html>`
                    }
                },
                Subject: {
                    Charset: "UTF-8",
                    Data: "Here's a sample email."
                }
            },
            Source: 'Sample Sender <[email protected]>'
        }

        ses.sendEmail(parameters,(err,data)=>{
            if(err) {
                document.write(err);
            } else {
                document.write("Done");
            }
        });
}

When I run the doGet() function, it shows me this error -

Why did this error show up and what should I do? Also I don't have any other code except this one. I searched for this error, and I found out that setTimeout is not defined error comes when there is some typo/mistake in using it - but my code doesn't seem to have any setTimeout function - what could be wrong? I've just started with JS & google apps script, hence I am a bit confused... Kindly advice... Thanks! :)

P.S. The whole AWS code works properly when tested in a proper JS file externally.

12
  • 1
    From your showing script, the script of https://sdk.amazonaws.com/js/aws-sdk-2.1206.0.min.js is for Javascript. In the case of Google Apps Scrtipt, unfortunately, not all functions of Javascript cannot be used. In the case of your question, setTimeout cannot be used. And also, document.write cannot be used. Please be careful this. Ref1, Ref2, Ref3 Commented Sep 2, 2022 at 6:42
  • 1
    Thank you for replying. I apologize for the inconvenience. About What do you mean by In the case of your question, setTimeout cannot be used - i am not using settimeout in my code, I think that setTimeout is used in the script of https://sdk.amazonaws.com/js/aws-sdk-2.1206.0.min.js. When you will check the script, I think that you can see it. Commented Sep 2, 2022 at 6:48
  • 1
    About What method should I use if I still want to use the aws js sdk in my apps script? or is it not doable?, in this case, I think that there might be 2 patterns. 1. Modify the script of https://sdk.amazonaws.com/js/aws-sdk-2.1206.0.min.js for Google Apps Script. 2. Directly request to the endpoint of the API using Google Apps Script. Commented Sep 2, 2022 at 6:51
  • 1
    Thank you for replying. About In the second pattern, do you mean the AWS SES API?, if you want to send an email using Amazon SES API, I think that it's yes. Commented Sep 2, 2022 at 6:55
  • 1
    About do you know any introductory articles? and will I be able to integrate that rest api in google apps script?, although I'm not sure whether I could correctly understand your goal, is this document useful? docs.aws.amazon.com/ses/latest/dg/send-email-api.html Commented Sep 2, 2022 at 7:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.