Issue - When connection.close is called (after calling client.sendAsync) an uncaught error gets triggerd:
TypeError: domain.enter is not a function
at SMTPConnection.emit (node:domain:551:10)
Cause - This behavior was introduced in v5.0.1 on fix for #350
Reason - NodeJS's deprecated internal 'node:domain' module assumes a EventEmitter's domain property is an object whenever you call .emit - Relevant node.js code. I found this because the node:repl module imports the domain module in node version 24 (not in v26)
To Reproduce -
// in node v24 imports the 'domain' module
import node_repl from "node:repl";
// this till trigger issue in v26 as well
import domain from "node:domain";
import { SMTPClient } from 'emailjs';
const client = new SMTPClient({ host: '127.0.0.1', port: 25 });
// triggers error
client.smtp.close();
// TypeError: domain.enter is not a function
// at SMTPConnection.emit (node:domain:551:10)
Possible fixes - rename SMTPConnection.domain to _domain, use EventTarget instead of EventEmitter, or other reference method?
Workaround
import { SMTPClient } from 'emailjs';
import { EventEmitter } from 'node:events';
const client = new SMTPClient({ host: '127.0.0.1', port: 25 });
// check if node:domain behavior is active
if (EventEmitter.usingDomains) {
const domainName = client.smtp.domain ?? '';
// mock the Domain object
client.smtp.domain = {
enter() {},
exit() {},
// still treated as a string otherwise
[Symbol.toPrimitive](hint) {
return hint === 'string' ? domainName : null;
}
}
}
Issue - When connection.close is called (after calling client.sendAsync) an uncaught error gets triggerd:
Cause - This behavior was introduced in v5.0.1 on fix for #350
Reason - NodeJS's deprecated internal
'node:domain'module assumes a EventEmitter'sdomainproperty is an object whenever you call.emit- Relevant node.js code. I found this because thenode:replmodule imports the domain module in node version 24 (not in v26)To Reproduce -
Possible fixes - rename
SMTPConnection.domainto_domain, useEventTargetinstead ofEventEmitter, or other reference method?Workaround