I imported the aws-sdk module and this is my code on the backend module :
import {aws} from ‘aws-sdk’;
export function sendEmail() { console.log(aws)
}
This my code on the client side:
export function button1_click(event) {
sendEmail().then(product => {
console.log(product);
})
. catch (error => {
console.log(error);
});
}
You are simply console logging ‘aws’ in the backend.
I’m pretty sure you need Access (API) Keys to authorize your call and you need to use their .sendEmail() function to send all the parameters (body, sender, recipient)
Thank you for the quick response. My point from the above code is that I am not able to load aws module at all in my backend code. So without that I can’t call send email anyways, so i am trying to solve that first .
I used the code from your example like this: import {AWS} from ‘aws-sdk’;
export function sendEmail() {
// Set the region const ses = new AWS.SES(); const params = {
Destination: {
ToAddresses: [‘to-email@example.com’]
},
Message: {
Body: {
Html: {
Charset: ‘UTF-8’,
Data:
‘This message body contains HTML formatting, like Amazon SES Developer Guide.’
},
Text: {
Charset: ‘UTF-8’,
Data: ‘This is the message body in text format.’
}
},
Subject: {
Charset: ‘UTF-8’,
Data: ‘Test email from code’
}
},
ReturnPath: ‘from-email@example.com’,
Source: ‘from-email@example.com’
};
ses.sendEmail(params, (err, data) => { if (err)
console.log(err, err.stack); else
console.log(data);
});
}
Th error I got when I executed the above code is :
TypeError: Cannot read property ‘SES’ of undefined
So its failing in the first step itself and I am not sure why its unable to load AWS from aws-sdk .
Call the backend function emailing() from your page to test and you will see that it has loaded correctly and will be throwing the correct errors for the above code.