how to send email use nodemailer on local host postfix mail server with SSL - ssl

I have set up postfix email server on my DigitalOcean cloud server. Now I want to send email from my program using nodeMailer. I try this setting and success
var transporter = nodemailer.createTransport({
host: "localhost", // hostname
secure: false, // use SSL
port: 25, // port for secure SMTP,
tls: {
rejectUnauthorized: false
}
});
the email were sent in the spam folder on the target recipient Email address.So I think maybe secure:false is reason. So how can I enable SSL?

Related

IPFS Http Client Link Access without Token

I’m following the code here(https://infura.io/docs/ipfs#section/Authentication/Using-ipfs-http-client-in-JS 7) and I’m able to add to IPFS without the auth token in the header (my code below). How is this possible?
const client = create({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
});

Sending a self-signed certificate from proxy secure websocket to a secure websocket connection(wss)

I am trying to connect to wss(proxy) with self-signed certificate using wscat and browser but it giving me errors.
https running on 8443 with certificate cert.pem
proxy running on 8080 with secure true
Things I have tried to make sure my secure server is running properly.
I can reach https://localhost:8443 and receive "hello from a secure world"
I can connect to wss://localhost:8443 with wscat wscat -c wss://localhost:8443 --ca cert.pem and it works
Errors I get:
I cannot reach the proxy https://localhost:8080 from browser. I get This site can’t provide a secure connection and 500 status code
I cannot connect to wss://localhost:8080 with wscat -c wss://localhost:8080 --ca cert.pem I get error: write EPROTO 140266887743360:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
What I think the issue is that my proxy server is unable to take the cert.pem and pass it to the https server. I have looked everywhere but I can't find how to connect to wss(proxy) with a self-signed certificate. I can't supress the
/server
const app = express()
app.use('/', function (req, res) {
res.writeHead(200);
res.end("hello from a secure world\n");
})
export const server = https.createServer({
cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem'), 'utf-8'),
ca: fs.readFileSync(path.resolve(__dirname, 'cert.pem'), 'utf-8'),
key: fs.readFileSync(path.resolve(__dirname, 'server.key'), 'utf-8')
}, app)
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
console.log("connected");
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send('hello from server!, the time is: ' + timestamp());
});
});
/Proxy
const wsProxy = createProxyMiddleware('/', {
target: `https://localhost:8443`,
changeOrigin: true,
secure: true,
ws: true,
ssl: {
cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem')),
}
});
const app = express();
app.use(wsProxy);
const proxy = app.listen(8080)
proxy.on('upgrade', wsProxy.upgrade); // <-- subscribe to http 'upgrade'
Okay, it turned out that I was missing something crucial there. There wasn't really a "proxy websocket" I was confusing https proxy with websocket proxy. Once I made sense of that it solved my problem. I had to create a websocket with using https server(with cert and key) then I could just connect to the wss with the same cert and key :)

How to fix "errno":"ENOTFOUND" error in smtp configuration using express js

I am trying to configure node mailer in express js application. During the time of sending mail, I got an error ENOTFOUND.
My smpt configurations are,
smtpServer: {
host: "smtp.gmail.com",
port: 587,
secure: false,
user: "email#gmail.com",
pass: "password",
fromName: "",
fromAddress: ""
}
Error :
{"errno":"ENOTFOUND","code":"ECONNECTION","syscall":"getaddrinfo","hostname":"smtp.gmail.com","host":"smtp.gmail.com","port":587,"command":"CONN","meta":{"errno":"ENOTFOUND","code":"ECONNECTION","syscall":"getaddrinfo","hostname":"smtp.gmail.com","host":"smtp.gmail.com","port":587,"command":"CONN"}}
I suspect this error came because of proxy issues. So, I checked the smpt hostname in my machine nslookup table.
That is returned following result:
$ nslookup smtp.gmail.com
Server: 127.0.1.1
Address: 127.0.1.1#53
Non-authoritative answer:
*** Can't find smtp.gmail.com: No answer
Other than else what I missed here?

How to send encrypted/TLS emails with NodeJS from localhost using send mail

I want to be able to send emails from my local domain without using gmail or other SMTP servers.
I'm currently using SendMail:
const sendmail = require('sendmail') ({
logger: {
debug: console.log,
info: console.info,
warn: console.warn,
error: console.error
},
dkim: {
privateKey: dkimPrivateKey,
keySelector: 'default'
},
});
sendmail({
from: 'foo#mydomain.com',
to: 'mygmail#gmail.com',
subject: 'test sendmail',
html: 'Mail of test sendmail ',
}, function(err, reply) {
console.log(err && err.stack);
console.dir(reply);
});
and this DOES work, BUT when I receive the email in my Gmail account, and I view the message information, Google is marking this as 'security: No encryption'
From what I understand I need to use TLS to create a 'secure' connection. I already have a certificate and keys from LetsEncrypt and my domain is already using HTTPS. How do I encrypt/use TLS my outgoing emails?
Or is there a better package for this? I've tried using NodeMailer and my emails only get added to a 'queue' and never sent. What is the problem?

WARNING, Unable to connect to cloud code on https

After setting up parse on https I receive this message .
'WARNING, Unable to connect to https://localhost:2096/parse'.
Cloud code and push notifications may be unavailable!
here is my configuration :
serverURL: 'https://localhost:2096/parse',
publicServerURL: 'https://core.com:2096/parse',
var credentials = {key: privateKey, cert: certificate};
var port = 2096;
var httpsServer = require('https').createServer(credentials, app);
any idea how to make it work ?
Regards