I have successfully uploaded the Nodemailer npm dependency in my Mongo Realm functions and now trying to send an email when a document in my Users collection is added. I use the following code:
exports = function(changeEvent) {
const {fullDocument} = changeEvent;
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'my-gmail-address',
pass: 'my-gmail-password'
}
});
const mailOptions = {
from: 'from-gmail-address',
to: 'to-email-address',
subject: 'New User',
html: `<p>email content with new user info</p>`
};
return transporter.sendMail (mailOptions, (error, info) => {
if (error) {
console.log(error);
return;
}
console.log('Sent Successfully!');
});
};
The function is triggered at document insert, but I keep getting an error that “hostname” is not a function. Any idea what the problem is?