why receiver not getting emails using Nodemailer? - node.js

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" });
};
});

Related

Nodemailer Godaddy relayer smtp connection timed out

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.

Can a push notification be send from the server without a client call?

I have a javascript file on my NodeJS server that runs at 00:00:00 and updates some fields in the database, if that happens I want to send out a push notification to some users. I've set this up in my Javascript file:
https://dev.to/devsmranjan/web-push-notification-with-web-push-angular-node-js-36de
const subscription = {
endpoint: '',
expirationTime: null,
keys: {
auth: '',
p256dh: '',
},
};
const payload = {
notification: {
title: 'Title',
body: 'This is my body',
icon: 'assets/icons/icon-384x384.png',
actions: [
{action: 'bar', title: 'Focus last'},
{action: 'baz', title: 'Navigate last'},
],
data: {
onActionClick: {
default: {operation: 'openWindow'},
bar: {
operation: 'focusLastFocusedOrOpen',
url: '/signin',
},
baz: {
operation: 'navigateLastFocusedOrOpen',
url: '/signin',
},
},
},
},
};
const options = {
vapidDetails: {
subject: 'mailto:example_email#example.com',
publicKey: process.env.REACT_APP_PUBLIC_VAPID_KEY,
privateKey: process.env.REACT_APP_PRIVATE_VAPID_KEY,
},
TTL: 60,
};
webpush.sendNotification(subscription, JSON.stringify(payload), options)
.then((_) => {
console.log(subscription);
console.log('SENT!!!');
console.log(_);
})
.catch((_) => {
console.log(subscription);
console.log(_);
});
But when I run the file I get the message:
{ endpoint: '', expirationTime: null, keys: { auth: '', p256dh: '' } } Error: You must pass in a subscription with at least an endpoint.
Which makes sense since the server has no idea about service workers etc. Any suggestions on how to proceed?

sending mail in node.js, nodemailer

I wan to send mail with only nodemailer. With out other transport system.
below i have given my configuration.
I didn't received any mail, but response showing the mail is successfully send.
Username: sendbox#name.com
Password: ajsdkasd
Incoming Server: mail.name.com
IMAP Port: 993 POP3 Port: 995
Outgoing Server: mail.name.com
SMTP Port: 465
my node mailer configuration is
var Mailer = require("nodemailer");
var transportar = Mailer.createTransport({
service: "smtp",
host: "mail.name.com",
port: 465,
auth: {
user: "sendbox#name.com",
pass: "jsdkfjksd",
},
});
and
var mailOptions = {
from: "sendbox#name.com",
to: req.body.email,
subject: "Email Subjects",
html: "<h1>Welcome Reciver</h1>",
};
const sendEmail = await transportar.sendMail(mailOptions)
the response is
"email": {
"accepted": [
"name#gmail.com"
],
"rejected": [],
"envelopeTime": 36,
"messageTime": 4,
"messageSize": 311,
"response": "250 OK id=1jnlkk-0006FS-IO",
"envelope": {
"from": "sendbox#name.com",
"to": [
"name#gmail.com"
]
},
"messageId": "<cf7fbe92-c59a-9884-5061-77b95c3dcfba#name.com>"
},

Email-Templates/Nodemailer emails not containing template

I'm trying to send an ejs template with email-templates but I'm not having much joy.
The email sends fine, however it doesn't contain any template data.
const email = new Email ({
template: 'activateAccount',
message: {
from: "noreply#domain.com",
subject: "Activate your account!",
to: data.email
},
locals: {
name: data.name,
url: data.url
},
send: true,
transport: {
host: "domain.com",
port: 2525,
auth: {
user: "abc",
pass: "123"
}
},
views: {
options: {
extension: 'ejs'
}
}
});
return await email.send();
Does anyone know why the templates aren't being populated?
Use the locals when .sending the email,
const email = new Email({
message: {
from: "noreply#domain.com",
subject: "Activate your account!",
to: data.email
},
send: true,
transport: {
host: "domain.com",
port: 2525,
auth: {
user: "abc",
pass: "123"
}
},
views: {
options: {
extension: 'ejs'
}
}
});
await email.send({
template: 'activateAccount',
locals: {
name: data.name,
url: data.url
}
});
Basically, you can use all the options is .send function itself.

Nodemailer is not able to send mail using aws on production server

I am getting the problem while sending mails through nodemailer and AWS. Following are the my settings :
var transporter = nodemailer.createTransport("SMTP", smtpTransport({
host: 'email-smtp.us-west-2.amazonaws.com',
service: 'SES',
port: 25,
secure: true,
debug: true,
auth: {
user: 'XXX',
pass: 'XXX'
}
}));
Mail sending code:
transporter.sendMail({
from: xxx#xxx.com,
to: xxx#xxx.com,
subject: 'XXX',
html: 'XXX'
}, function(error, response) {
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
});
I am getting following error:
{ [Error: connect ECONNREFUSED 127.0.0.1:25]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 25,
stage: 'init' }
Here's what my transporter object look like when I printed it :
Transport {
options:
SMTPTransport {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
options:
{ host: 'email-smtp.us-east-1.amazonaws.com',
service: 'SES',
port: 465,
secure: true,
debug: true,
auth: [Object] },
logger: { info: [Function], debug: [Function], error: [Function] },
name: 'SMTP',
version: '2.4.1[client:2.3.1]',
maxConnections: 5,
maxMessages: Infinity },
transportType: 'SMTP',
dkimOptions: false,
transport:
SMTPTransport {
options:
SMTPTransport {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
options: [Object],
logger: [Object],
name: 'SMTP',
version: '2.4.1[client:2.3.1]',
maxConnections: 5,
maxMessages: Infinity },
pool:
SMTPConnectionPool {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
port: 25,
host: 'localhost',
options: [Object],
_connectionsAvailable: [],
_connectionsInUse: [Object],
_messageQueue: [Object],
_idgen: 2 } },
version: '0.3.35',
sendMail: [Function] }
As you can clearly see it is using different setting then defined by me.
I am unable to find the issue. Any help will be appreciated.
if you want to send mail through aws it is better to use aws-sdk module. usage is given below
var aws = require('aws-sdk');
module.exports = function (to, from, sub, body) {
aws.config.update({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
region: 'region'
});
// load AWS SES
var ses = new aws.SES({apiVersion: 'latest'});
// this sends the email
ses.sendEmail({
Source: from,
Destination: {
ToAddresses: to
},
Message: {
Subject: {
Data: sub
},
Body: {
Html: {
Data: body
}
}
}
}
, function (err, data) {
if (err) {
console.log(err);
} else {
console.log('Email sent:');
console.log(data);
}
});
};
Hope it helps :)

Resources