generic3892372
generic3892372

Reputation: 206

How to configure SMTPServer options with pem key and cert?

The guidance here: https://nodemailer.com/extras/smtp-server/ ... indicated that I should configure my SMTP server (in production) like so:

Example code from nodemailer site:

const server = new SMTPServer({
  secure: true,
  key: fs.readFileSync("private.key"),
  cert: fs.readFileSync("server.crt"),
});
server.listen(465);

My code:

  environmentSpecificOptions = {
    secure: false,
    disabledCommands: ['AUTH'],
    key: fs.readFileSync("/etc/letsencrypt/live/api.mywebsite.org/privkey.pem"),
    cert: fs.readFileSync("/etc/letsencrypt/live/api.mywebsite.org/fullchain.pem"),
    name: process.env.SMTP_HOST, // mywebsite.org
    hideSize: false,
}

Current behavior: Sort of a black box result with no error message. Here is the output:

Message sent: <[email protected]>
sendResult: {"accepted":["[email protected]"],"rejected":[],"envelopeTime":4,"messageTime":44,"messageSize":762,"response":"250 OK: message queued","envelope":{"from":"[email protected]","to":["[email protected]"]},"messageId":"<[email protected]>"}

Failure result: I checked my email and did not receive any message. Yes, I checked spam and garbage folders as well, 2 days later.

My question: Why is this not sending? (variation of title)

Unrelated musings that may not be pertinent to the main question: Are most SMTP servers configured to use the cert and private key for the front-end web server? Because if I do it as I am now, my website users will receive an email from "api.mywebsite.org" instead of "mywebsite.org" which doesn't seem right to me.

My best guesses: Perhaps pem keys need to be handled differently, or perhaps I have to generate my own new key, separate from the website pem key that enables HTTPS? Or perhaps I should enable secure: true. Or perhaps I am required to enable authentication when using key & cert?

Upvotes: 0

Views: 123

Answers (0)

Related Questions