Nodemailer dependency with Realm functions

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: '',
    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('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?


I’m getting the exact same problem. Have you found a solution?

No. Unfortunately I couldn’t find a solution. What I did was to write my nodemailer code in my backend API (Express/NodeJs) and use the Realm trigger to send a request to that API endpoint instead.

Same issue here. Has anybody a working solution?

I couldn’t make it work, I’ll probably end up doing the same as @Akbar_bakhshi1. Although it would be cool to be able to use this library in Realm functions.

Hi All,

Nodemailer has a dependency for Punycode which is currently an unsupported module in Realm Functions as mentioned in this article, and is likely the cause of the error.

Realm functions do not support the following built-in modules:

  • child_process
  • cluster
  • domain
  • punycode
  • readline
  • v8
  • vm

Our team is looking to provide Punycode support at some point in the future, however we do recommend using a service such as AWS SES for sending out emails. This will be a more reliable alternative especially if you are sending with high frequency/volume.


1 Like

Just if for Info I created a feedback idea you can vote:

I believe we have very recently added support for Punycode.
The documentation on this is yet to be updated.


1 Like

still have the error:

{“message”:“The ‘hostname’ argument must be of type string”,“code”:“ECONNECTION”,“command”:“CONN”}

kind regards