Hi,
I’m pretty new to all this stuff. I’m trying to add a code block to my workflow that sends an email generated with data from a prior step using nodemailer
.
My code works correctly if I don’t don’t wrap it inside export default defineComponent({ async run({ steps, $ }) { ... }, })
But then the steps
object is undefined.
If I wrap it in the async function, my code runs a test successfully, but doesn’t actually send the email. Anyone see what I’m doing wrong? Thank you!!
Here’s my code:
import nodemailer from 'nodemailer'
export default defineComponent({
async run({ steps, $ }) {
// Get new member's details
const recipientEmail = steps.get_record.$return_value.fields["member-email"]
const recipientName = steps.get_record.$return_value.fields["member-name"]
const inviteCode = steps.get_record.$return_value.fields["invite-code"]
// Create the message
const message = `
Hey ${recipientName} - So great to hear from you and thanks so much for your interest in our ogranization. We're excited to have you join the community!
Best way to jump in is to join our Discord here (https://discord.js.org/${inviteCode}).`
// configure the mail transport
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
auth: {
user: process.env.GMAIL_USERNAME,
pass: process.env.GMAIL_PASSWORD_PIPEDREAM
}
});
const mailOptions = {
from: process.env.GMAIL_USERNAME,
to: recipientEmail,
subject: 'Welcome aboard!',
text: message
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
},
})