mx-connect
Advanced tools
Comparing version 1.0.10 to 1.1.0
@@ -137,2 +137,8 @@ 'use strict'; | ||
let emitConnectError = err => { | ||
if (typeof delivery.connectError === 'function') { | ||
delivery.connectError(err, delivery, options); | ||
} | ||
}; | ||
//plugins.handler.runHooks('sender:connect', [delivery, options], err => { | ||
@@ -174,3 +180,3 @@ emitConnectHook(err => { | ||
socket.once('error', err => { | ||
if (err && !firstError) { | ||
if (err) { | ||
let code = 450; | ||
@@ -182,3 +188,6 @@ err.message = `Network error when connecting to MX server ${mx.hostname}[${mx.host}] for ${delivery.domain}: ${netErrors[err.code] || | ||
err.category = err.category || 'network'; | ||
firstError = err; | ||
emitConnectError(err); | ||
if (!firstError) { | ||
firstError = err; | ||
} | ||
} | ||
@@ -196,7 +205,9 @@ clearTimeout(connectTimeout); | ||
connected = true; | ||
let code = 450; | ||
let err = new Error(`Connection timed out when connecting to MX server ${mx.hostname}[${mx.host}] for ${delivery.domain}`); | ||
err.response = code + ' ' + err.message; | ||
err.category = 'network'; | ||
emitConnectError(err); | ||
if (!firstError) { | ||
let code = 450; | ||
firstError = new Error(`Connection timed out when connecting to MX server ${mx.hostname}[${mx.host}] for ${delivery.domain}`); | ||
firstError.response = code + ' ' + firstError.message; | ||
firstError.category = 'network'; | ||
firstError = err; | ||
} | ||
@@ -203,0 +214,0 @@ return setImmediate(tryNextMX); |
{ | ||
"name": "mx-connect", | ||
"version": "1.0.10", | ||
"version": "1.1.0", | ||
"description": "Establish TCP connection to a MX server", | ||
@@ -26,3 +26,3 @@ "main": "lib/mx-connect.js", | ||
"eslint-config-nodemailer": "^1.2.0", | ||
"eslint-config-prettier": "^3.0.1", | ||
"eslint-config-prettier": "^3.1.0", | ||
"grunt": "^1.0.3", | ||
@@ -29,0 +29,0 @@ "grunt-cli": "^1.3.1", |
@@ -20,4 +20,4 @@ # mx-connect | ||
* **options** is the target domain, address, or configuration object | ||
* **callback** is the function to run once connection is established to it fails | ||
- **options** is the target domain, address, or configuration object | ||
- **callback** is the function to run once connection is established to it fails | ||
@@ -47,19 +47,20 @@ **Example** | ||
* **target** is either a domain name or an email address or an IP address or IP address literal (basically anything you can have after the @-sign in an email address). Unicode is allowed. | ||
- **target** is either a domain name or an email address or an IP address or IP address literal (basically anything you can have after the @-sign in an email address). Unicode is allowed. | ||
* **port** is the port number to connect to. Defaults to 25. | ||
* **localAddress** is the local IP address to use for the connection | ||
* **localHostname** is the hostname of the local address | ||
* **localAddressIPv4** is the local IPv4 address to use for the connection if you want to specify an address both for IPv4 and IPv6 | ||
* **localAddressIPv6** is the local IPv6 address to use for the connection if you want to specify an address both for IPv4 and IPv6 | ||
* **dnsOptions** is an object for IP address related options | ||
* **ignoreIPv6** (boolean, defaults to `false`) If true then never use IPv6 addresses for sending | ||
* **preferIPv6** (boolean, defaults to `false`) If true then use IPv6 address even if IPv4 address is also available | ||
* **blockLocalAddresses** (boolean, defaults to `false`) If true then refuses to connect to IP addresses that are either in loopback, private network or attached to the server. People put every kind of stuff in MX records, you do not want to flood your loopback interface because someone thought it is a great idea to set 127.0.0.1 as the MX server | ||
* **mx** is a resolved MX object or an array of MX objects to skip DNS resolving. Useful if you want to connect to a specific host. | ||
* **exchange** is the hostname of the MX | ||
* **priority** (defaults to 0) is the MX priority number that is used to sort available MX servers (servers with higher priority are tried first) | ||
* **A** is an array of IPv4 addresses. Optional, resolved from exchange hostname if not set | ||
* **AAAA** is an array of IPv6 addresses. Optional, resolved from exchange hostname if not set | ||
* **connectHook** _function (options, socketOptions, callback)_ is a function handler to run before establishing a tcp connection to current target (defined in `socketOptions`). If the `socketOptions` object has a `socket` property after the callback then connection is not established. Useful if you want to divert the connection is ome cases, for example if the target domain is in the Onion network then you could create a socket against a SOCK proxy yourself. | ||
- **port** is the port number to connect to. Defaults to 25. | ||
- **localAddress** is the local IP address to use for the connection | ||
- **localHostname** is the hostname of the local address | ||
- **localAddressIPv4** is the local IPv4 address to use for the connection if you want to specify an address both for IPv4 and IPv6 | ||
- **localAddressIPv6** is the local IPv6 address to use for the connection if you want to specify an address both for IPv4 and IPv6 | ||
- **dnsOptions** is an object for IP address related options | ||
- **ignoreIPv6** (boolean, defaults to `false`) If true then never use IPv6 addresses for sending | ||
- **preferIPv6** (boolean, defaults to `false`) If true then use IPv6 address even if IPv4 address is also available | ||
- **blockLocalAddresses** (boolean, defaults to `false`) If true then refuses to connect to IP addresses that are either in loopback, private network or attached to the server. People put every kind of stuff in MX records, you do not want to flood your loopback interface because someone thought it is a great idea to set 127.0.0.1 as the MX server | ||
- **mx** is a resolved MX object or an array of MX objects to skip DNS resolving. Useful if you want to connect to a specific host. | ||
- **exchange** is the hostname of the MX | ||
- **priority** (defaults to 0) is the MX priority number that is used to sort available MX servers (servers with higher priority are tried first) | ||
- **A** is an array of IPv4 addresses. Optional, resolved from exchange hostname if not set | ||
- **AAAA** is an array of IPv6 addresses. Optional, resolved from exchange hostname if not set | ||
- **connectHook** _function (options, socketOptions, callback)_ is a function handler to run before establishing a tcp connection to current target (defined in `socketOptions`). If the `socketOptions` object has a `socket` property after the callback then connection is not established. Useful if you want to divert the connection is ome cases, for example if the target domain is in the Onion network then you could create a socket against a SOCK proxy yourself. | ||
- **connectError** _function (err, options, socketOptions)_ is a function handler to run when a connection to a MX fails. | ||
@@ -70,8 +71,8 @@ ### Connection object | ||
* **socket** is a socket object against target | ||
* **hostname** is the hostname of the exchange | ||
* **host** is the IP address of the exchange | ||
* **port** is the port used to connect | ||
* **localAddress** is the local IP address used for the connection | ||
* **localPort** is the local port used for the connection | ||
- **socket** is a socket object against target | ||
- **hostname** is the hostname of the exchange | ||
- **host** is the IP address of the exchange | ||
- **port** is the port used to connect | ||
- **localAddress** is the local IP address used for the connection | ||
- **localPort** is the local port used for the connection | ||
@@ -78,0 +79,0 @@ ## License |
55212
950
79