Open hayanisaid opened 6 years ago
Hi @hayanisaid your code is almost there! Let's get it working!
Presumably the ./templates
directory exists and contains the welcome
template ...?
The error is being thrown on Line 19
https://github.com/dwyl/sendemail/blob/b35dbe219087b8b6468cb1cd4cd82372ba97197a/lib/index.js#L19
Because set_template_directory
is called on Line 25 expecting the TEMPLATE_DIRECTORY
environment variable to be defined:
https://github.com/dwyl/sendemail/blob/b35dbe219087b8b6468cb1cd4cd82372ba97197a/lib/index.js#L25
If you follow the second step in the instructions to set your Environment Variables: https://github.com/dwyl/sendemail#2-set-your-environment-variables
create an .env
file in your project (and remember to add .env to your .gitignore file)
add the TEMPLATE_DIRECTORY
path to the .env
file:
export TEMPLATE_DIRECTORY=./templates
# also include your AWS keys here they are not already in your environment.
and then update your code to:
var sendemail = require('sendemail');
var options = {
templateName: 'welcome',
context: {
tempalateVariableName: 'Variable Value',
name: 'Joe Bloggs'
},
subject: 'Welcome to Email',
senderEmailAddress: 'me@gmail.com',
toAddresses: ['me@gmail.com', 'me@gmail.com'],
htmlCharset: 'utf16',
textCharset: 'utf16',
subjectCharset: 'utf8'
};
sendemail.sendMany(options, callback);
It should work. Let us know your progress! Thanks for opening this issue and Welcome to dwyl! 🎉
Hi @nelsonic , Thank you for reply I already did this and the error still the same, and Installed env2 ,and when I run this code it work,I have .env file and work normally!
const env = require('env2')('.env');
// your app goes here
console.log(process.env.TEMPLATE_DIRECTORY) // output ./templates
but when I run sendmail function it doesn't work !!!
Hmm... that's very strange... 😕 Could you try the following:
git clone https://github.com/dwyl/sendemail.git
cd sendemail
npm install
cd examples
vi .env
# copy the values in the .env file in your project into this new file
node send-welcome-email.js
Let us know if that works (as a "baseline" of functionality) Thanks!
no, it didn't work.
throw new Error('Please Set a Template Directory'); ^
Error: Please Set a Template Directory
at set_template_directory (/Users//Desktop/DESKTOP/APP/aws-email2/sendemail/lib/index.js:19:11)
at Object.
I got this error, even the path directory to templates is correct this is My Code :100: