Closed gcphost closed 4 years ago
@gcphost the region is configurable precisely because of that line:
https://github.com/dwyl/sendemail/blob/b35dbe219087b8b6468cb1cd4cd82372ba97197a/lib/index.js#L10
If you want to define your SES Region to be different from the Lambda
simply set process.env.AWS_REGION
before you require('sendemail')
e.g your Lambda is running in California us-west-1
but you can only send email from Oregon us-west-2
...
process.env.AWS_REGION = 'us-west-2'; // set AWS_REGION for sending Emails via SES
var sendemail = require('sendemail');
var email = sendemail.email;
var person = {
name : "Jenny",
email: "your.name+test" + Math.random() + "@gmail.com", // person.email can also accept an array of emails
subject:"Welcome to DWYL :)"
}
email('welcome', person, function(error, result){
console.log(' - - - - - - - - - - - - - - - - - - - - -> email sent: ');
console.log(result);
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - -')
})
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html
Let us know how you get on with that approach.
Hi
Thank you.
Since I use other AWS services on Lambda I want to keep the default AWS_REGION
and not adjust it. Using your method I need to change the region back to the default after loading sendemail
, meaning some extra lines of code.
I ended up modifying it to accept another parameter first:
AWS.config.region = process.env.AWS_EMAIL_REGION || process.env.AWS_REGION;
Now I can use a different region without having to adjust any of my code.
Thanks for the quick reply and your package.
@gcphost sounds good. 👍
Closing as question answered. ✅
Hi
I was wanting to use your project with AWS Lambda but my Lambda is located in a region where SES is not available. Lambda sets the regions env var automatically.
Since SES is available in only 3 regions do you think it would be better to make the region value configurable outside of the env? https://github.com/dwyl/sendemail/blob/master/lib/index.js#L10
Thank you.