Skip to content

Instantly share code, notes, and snippets.

@andris9
Created March 4, 2023 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andris9/a13d9b327ea81d620ea89926d2097921 to your computer and use it in GitHub Desktop.
Save andris9/a13d9b327ea81d620ea89926d2097921 to your computer and use it in GitHub Desktop.
Custom DNS resolving with Nodemailer
// The following example sets up Nodemailer in a way that it does not perform any DNS resolving on its own
const hostname = 'smtp.gmail.com';
const resolved = (await dns.promises.resolve(hostname))[0];
const transporter = nodemailer.createTransport({
host: resolved, // <- IP address of the SMTP server
name: 'my.machine.hostname', // <- PTR name of sender's public IP address, ends up in the Recieved: header
tls: {
servername: hostname, // <- hostname of the SMTP server, needed to verify TLS
rejectUnauthorized: true, // <- allow only valid certs
minVersion: 'TLSv1.2' // <- allow TLSv1.2+, this matches MTA-STS requirements
},
port: 465,
secure: true,
auth: {
user: 'username',
pass: 'secret'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment