Nodemailer Godaddy relayer smtp connection timed out - node.js

so I am using the Godaddy smtp relayer service and trying to send email using the nestjs-moudles/mailere library for this which implements actually the nodemailer. It works locally fine but when deploying to the server I am getting a timeout issue.
here is the node mailer config:
export const MAIL_CONFIG: MailerOptions = {
transport: {
host: 'relay-hosting.secureserver.net',
port: 25,
tls: { rejectUnauthorized: false },
enableSsl: false,
secure: false,
secureConnection: false,
auth: {
user: config.mailer.user,
pass: config.mailer.pass
}
},
defaults: {
from: config.mailer.from
},
template: {
dir: path.resolve(__dirname, '../../modules/secondary/mail/templates'),
adapter: new HandlebarsAdapter(),
options: {
strict: true
}
}
};
Anyone can help with this?
expect to be able to send emails.

Related

why receiver not getting emails using Nodemailer?

In the console I can see:
Sending message <c188880-8889928-1149-89243441014#example.com> to <example#gmail.com>
This is how I'm configuring the transport:
nodemailer.createTransport({
name: "mail.example.com",
host: "mail.example.com",
port: 587,
secure: false,
auth: {
user: "reminders#example.com",
pass: PASSWORD, //
},
logger: true,
tls: {
rejectUnauthorized: false,
},
});
transporter.sendMail() function gives me this data:
{
accepted: [ 'example#gmail.com' ],
rejected: [],
envelopeTime: 2111,
messageTime: 842,
messageSize: 28925,
response: '250 OK id=198wlQ-exatqE-Lz',
envelope: {
from: 'reminders#example.com',
to: [ 'example#gmail.com' ]
},
messageId: '<ccddd9-8311-795e-00c1-7a43f27b6b70#example.com>'
}
It used to work, I don't know what's changed.
I've checked the spam/junk folders in the receiver's account.
Try this instead:
let transporter = nodemailer.createTransport(({
service: "Outlook365",
host: "smtp.office365.com",
port: "587",
tls: {
ciphers: "SSLv3",
rejectUnauthorized: false,
},
auth: {
user: "reminders#example.com",
pass: PASSWORD, //
}
}));
let info = {
from: 'reminders#example.com',
to: `${email}`,
subject: "Subject text",
html: `text`
};
transporter.sendMail(info, function (err) {
if (err) {
console.log(err);
} else {
res.json({ message: "Message sent" });
};
});

Node-mssql not able to connect to the server but with tedious it connects

currently i'am using tedious package to connect to the database and do operations but i would like to switch to node-mssql (seems less messy).
The problem i'm getting is connection timeout:
originalError: ConnectionError: Failed to connect to yyy:1433 in 15000ms
code: 'ETIMEOUT',
isTransient: undefined
}
My config with tedious :
const config = {
server: process.env.HOST, // update me
authentication: {
type: 'default',
options: {
userName: process.env.USER, // update me
password: process.env.PASS, // update me
},
},
options: {
// If you are on Microsoft Azure, you need encryption:
database: process.env.DB,
rowCollectionOnDone: true, // update me
},
};
My config with mssql :
const configMssql = {
user: process.env.USER,
password: process.env.PASS,
server: process.env.HOST, // update me
database: process.env.DB,
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000,
},
options: {
encrypt: false, // for azure
trustServerCertificate: false, // change to true for local dev / self-signed certs
},
};
or
const configMssqlString = `Server=${process.env.HOST},1433;Database=${process.env.DB};User Id=${process.env.USER};Password=${process.env.PASS};Encrypt=false`;
Can't figure out whats wrong

nodemailer + nestjs + #nestjs-modules/mailer not working with aws ses, giving `Error: Unexpected socket close` error

I am using AWS SES for SMTP credentials and this nestjs module #nestjs-modules/mailerit was working 4/5 days ago but suddenly, what happened 🤔
I am pretty sure that my credentials are right.
Error: Unexpected socket close
at Timeout._onTimeout
node_modules/nodemailer/lib/smtp-transport/index.js:189:31)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
transport: {
host: process.env.EMAIL_SERVER_HOST,
secure: false,
port: +process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
defaults: {
from: `${process.env.EMAIL_FROM}`,
},
template: {
dir: join(__dirname, 'templates'),
adapter: new HandlebarsAdapter(),
options: {
strict: true,
},
},
}),
Edit 1: it is working on the production environment, then why it is not working on my local machine, app is hosted on cloud run :(
I got it; it is because of the wifi I am using. If I use my mobile network, it works properly.
It works on the local environment and production environment as well. I hope it helps. It requires the AWS SES key and secret, the SES SMTP user and password and the correct region.
import { Module, Global } from '#nestjs/common';
import { MailerModule } from '#nestjs-modules/mailer';
import { HandlebarsAdapter } from '#nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { MailService } from './mail.service';
import { join } from 'path';
import { ConfigService } from '#nestjs/config';
import * as AWS from 'aws-sdk';
const upperCaseFn = (name: string) => {
return name.toUpperCase();
};
#Global()
#Module({
imports: [
MailerModule.forRootAsync({
useFactory: async (config: ConfigService) => ({
transport: {
SES: new AWS.SES({
region: config.get('AWS_SES_REGION'),
accessKeyId: config.get('AWS_SES_ACCESS_KEY'),
secretAccessKey: config.get('AWS_SES_KEY_SECRET'),
}),
host: config.get('MAIL_HOST'),
port: config.get('MAIL_PORT'),
secure: false,
ignoreTLS:true,
requireTLS:false,
auth: {
user: config.get('MAIL_USERNAME'),
pass: config.get('MAIL_PASSWORD'),
},
debug: true
},
defaults: {
from: `"${config.get('MAIL_FROM_NAME')}" <${config.get(
'MAIL_FROM_ADDRESS',
)}>`,
},
template: {
dir: join(__dirname, '/templates'),
adapter: new HandlebarsAdapter({ upperCase: upperCaseFn }), // or new PugAdapter() or new EjsAdapter()
options: {
strict: true,
},
},
options: {
partials: {
dir: join(__dirname, '/templates/partials'),
options: {
strict: true,
},
},
},
}),
inject: [ConfigService],
}),
],
providers: [MailService],
exports: [MailService],
})
export class MailModule {}

Migration with Sequelize CLI to DigitalOcean Postgres Database Throwing SSL Error

Connecting to my my DigitalOcean database with Sequelize works fine when I'm not migrating. For example, attempting to create a new table works just fine; the code below successfully connects and creates a new table.
sequelize = new Sequelize(config.use_env_variable, config);
sequelize.authenticate().then(console.log('success')).catch((error) => console.log(error));
sequelize.define('test-table', {
test_id: {
type: Sequelize.INTEGER,
},
});
sequelize.sync();
I have a CA certificate .crt file I downloaded from DigitalOcean that I'm passing in with the Sequelize options. My config.js looks like
development: {
use_env_variable: 'postgresql://[digitalocean_host_url]?sslmode=require',
ssl: true,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
ca: fs.readFileSync(`${__dirname}/../.postgresql/root.crt`),
},
},
},
However when I try to create tables using migrations with
npx sequelize-cli db:migrate
I receive the following output and error:
Parsed url postgresql://[digitalocean_host_url]?sslmode=require
ERROR: no pg_hba.conf entry for host [host], user [user], database [database], SSL off
Which is very strange, because SSL is working when I create a table using just Sequelize sync. I have a .sequelizerc file for the sequelize-cli configurations, which looks like this:
const path = require('path');
const env = process.env.NODE_ENV || 'development'
const config = require('./config/config')[env];
module.exports = {
'config': path.resolve('config', 'config.js'),
'url': config.use_env_variable,
'options-path': path.resolve('config', 'sql-options.json')
}
inside my sql-options.json I have the following
{
"use_env_variable": "postgresql://[digitalocean_host_url]?sslmode=require",
"dialect":"postgres",
"ssl": true,
"dialectOptions": {
"ssl": {
"required": true,
"rejectUnauthorized": true,
"ca": "/../.postgresql/root.crt"
}
}
}
I've tried a lot of the advice from various resources, including the sequelize/cli repo. But none of it seems to work. Any advice would be helpful.
I had the same issue and the fix was to add the code below in the migrations config file even though you already have it in the database connection file.
The following code is in the config/config.js file for migrations.
production: {
username: ****,
password: ****,
database: ****,
host: ****,
dialect: ****,
port: ****,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},
This is how my DB connection looks like that was working normally.
const sequelize = new Sequelize({
host: ****,
database: ****,
username: ****,
password: ****,
dialect: ****,
port: ****,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
});

How to broadcast same messages to multiple interfaces in Mosca

I have 2 interfaces, one mqtt and one for websocket. I noticed if I have a backend, the mqtt does not route to websocket.
I created the mosca server as below:
server = new mosca.Server(
{
interfaces:
[
{ type: "mqtt", port: 1883 },
{
type: "mqtts",
port: 8443,
credentials: { keyPath: SECURE_KEY, certPath: SECURE_CERT }
},
{ type: "http", port: 4000, bundle: true }
],
onQoS2publish: "noack",
logger: { name: 'MoscaServer', level: 'debug' },
backend: {
type: "mqtt",
json: false,
mqtt: require("mqtt"),
key: filesys.readFileSync(__dirname + "/certs/private.key"),
cert: filesys.readFileSync(__dirname + "/certs/cert.pem"),
ca: filesys.readFileSync(__dirname + "/certs/rootCA.cer"),
clientId: "randomClientId",
port: 8883,
host: "<aws IOT endpoint>.iot.<aws region>.amazonaws.com",
rejectUnauthorized: false,
protocol: "mqtts"
},
}
);
What do I need to do to route between all the 3: mqtt, websocket and the backend?
Thanks!

Resources