I am trying to send a mail from node using nodemailer. I tried to send using ethereal for testing, but i keep getting connection refused error.
const createAutoEmail = require("../functionLib/autoEmail");
const config = {
type: "service",
host: "smtp.ethereal.email",
port: 587,
secure:false,
auth: {
user: "[email protected]",
pass: "Sg7f8z2r2Yyhs8hppZ",
},
defaultFrom: "[email protected]",
templates: {
welcome: {
subject: `Welcome to our Community`,
body: `<h1>Hi {{name}}</h1><p>Thanks for joining our community. We are happy to have you here.</p>`,
},
},
schedules: {},
};
async function test() {
const autoEmailer = createAutoEmail(config);
await autoEmailer.initialize();
// Check if the 'welcome' template exists
if (!config.templates.welcome) {
console.error("Template 'welcome' not found in config.");
return;
}
try {
await autoEmailer.sendScheduledEmail("welcome", "[email protected]", {
name: "John",
});
console.log("Email sent successfully");
} catch (error) {
console.error("Error sending email:", error);
}
autoEmailer.shutdown();
}
test();
I tried to execute like this.when i run this file i keep getting error message.
This is my first time using nodemailer and i am not able to find the error in it.
New contributor
sumanth kishor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.