Incomplete response received from application NodeJS running on Plesk - node.js

i have a controller that sends email with nodemailer.
my app is running o plesk.
when i run it in my localhost every thing is ok. but when i run it on host with plesk i get this error :
Incomplete response received from application
my function :
submitInvoice = async (req, res, next) => {
try {
var transporter = mailer.createTransport({
host: process.env.mailhost,
port: 587,
auth: {
user: process.env.mailuser,
pass: process.env.mailPass,
},
tls: { rejectUnauthorized: false },
});
var mailOptions = {
from: process.env.mailuser,
to: process.env.reciever,
subject: "", // Subject line
// attachments: [{ filename: "new-form.xlsx", content: data }],
html:
"<!DOCTYPE html>" +
"<html><head><title>title </title>" +
"<style>" +
"body {background-color:#ffdd00;background-repeat:no-repeat;background-position:top left;background-attachment:fixed;}" +
"h2{font-family:Arial, sans-serif;color:#000000;background-color:#ffdd00;text-align:center;}" +
"p {text-align:center;font-family:Georgia, serif;font-size:19px;font-style:normal;font-weight:bold;color:#000000}" +
"</style>" +
"</head><body><div>" +
" <h2>فایل اکسل پیوست شد</h2>" +
"</div></body></html>",
};
await transporter.sendMail(mailOptions);
return res.render("client/Counseling");
} catch (err) {
next(err);
}
};
the out put of nodemailer is :
250 2.0.0 Ok: queued as 9A795414F662E
do you have any idea what the problem is ?

Related

Can't send inline image with SendGrid gmail. But works with nodemailer + zoho

I'm following this tutorial to send embedded images in SendGrid.
SendGrid
I cannot get the image to load in SendGrid.
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: 'somemail#gmail.com', // Change to your recipient
from: 'company#company.com', // Change to your verified sender
subject: 'SendGrid',
html: `<strong>Some Text ${Date.now()}</strong><div style="border:10px solid blue;"><img src="cid:image123" alt="test image"/></div>`,
files: [
{
filename: 'image.jpg',
contentType: 'image/jpeg',
cid: 'image123',
content: `https://i.picsum.photos/id/1069/536/354.jpg?hmac=ywdE7hQ_NM4wnxJshRkXBsy-MHlGRylyqlb51WToAQA`,
disposition: 'inline',
},
],
};
sgMail
.send(msg)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
I also tried it with a base 64 string
const buf = '_9j_4AAQSkZJRgABAQAASABIAAD_4QguRXhpZgAATU0AKgAAAAgADAEPAAIAAAAGAAAAngEQAAIAAAAJAAAApAESAAMAAAABAAEAAAEaAAUAAAABAAAArgEbAAUAAAABAAAAtgEoAAMA.....
...
content: `data:image/png;base64,${buf}`,
Zoho & Nodemailer
However the image does load using Nodemailer so I don't think it's gmail that's causing the issue.
I able to get inline images to show when using nodemailer with zoho:
const nodemailer = require('nodemailer');
try {
const transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 587,
secure: false,
auth: {
user: <zoho_user>,
pass: <zoho_password>,,
},
});
const options = {
from: 'Company Name <company#company.com>',
to: 'someemail#gmail.com',
subject: 'Zoho email',
html: `<strong>Some Text ${Date.now()}</strong><img style="border: 10px solid orange;" src="cid:image123" />`,
attachments: [
{
filename: 'image.png',
path:
'https://i.picsum.photos/id/1069/536/354.jpg?hmac=ywdE7hQ_NM4wnxJshRkXBsy-MHlGRylyqlb51WToAQA',
cid: 'image123',
},
],
};
const sendZoho = async () => {
return await new Promise((res, rej) =>
transporter.sendMail(options, (error, info) => {
if (error) rej(error);
else res(info);
transporter.close();
})
);
};
const res = await sendZoho();
How can I send inline images to gmail with SendGrid?

Data command failed: 421 4.3.0 Temporary System Problem. Try again later (10) - gsmtp

I have deployed an HTTPS Function on Firebase, and I always get this error when I'm trying to send emails in bulk. I am using nodemailer pool to send emails.
Error: Data command failed: 421 4.3.0 Temporary System Problem. Try again later (10) - gsmtp
Client-side code:
export const sendEmails = async () => {
// Fetch All Users
let users = []
let data = await db.collection('users')
data.forEach(e => {
let data = e.data()
let email = data['email']
users.push({ email })
})
// Divide users into multiple batches of 25
let batches = [[]], num = 0, batchSize = 25
Promise.all(users.map(batch => {
if (batches[num].length < batchSize) {
batches[num].push(batch)
} else {
batches.push([batch])
num++
}
}))
// Send Email Request for each batch with some cooldown time.
Promise.all(batches.map((batch, index) => {
setTimeout(async () => {
await sendBroadcast(batch)
}, 2000 * index)
}))
}
export const sendBroadcast = async (users) => {
const url = base + "sendBroadcast?"
const body = JSON.stringify({ users })
return await fetch(url, { method: "POST", body })
}
Server-side code:
let transporter = nodemailer.createTransport({
service: 'gmail',
pool: true,
maxConnections: 20,
maxMessages: 500,
auth: {
user: 'SOME EMAIL',
pass: 'SOME PASSWORD',
},
})
exports.sendBroadcast = functions.runWith({ timeoutSeconds: 540, memory: '2GB' }).https.onRequest((req, res) => {
cors(req, res, () => {
const body = JSON.parse(req.body)
const users = body.users
console.log('info', 'Send email to ' + users.length + ' users')
users.forEach(function (to, index) {
var msg = {
from: 'SOME EMAIL',
to: to.email,
subject: "SUBJECT",
html: "<h2> SOME HTML </h2>",
}
return transporter.sendMail(msg, (erro, info) => {
if (erro) {
console.log('error', erro.message, 'failed to send to ' + email)
return res.status(500).send(erro.toString())
}
return res.send('sent')
})
})
})
})
Is this because gmail limits number of emails per day? I read somewhere that it would work if I added cooldowns after each email, I tried that as well but I was getting "Client network socket disconnected before secure TLS connection was established" error. Here's the Stack Overflow thread for that issue: Firebase Function Error "Client network socket disconnected before secure TLS connection was established" when sending bulk emails via Nodemailer

Relay server of godaddy server issue with express app contact form

From my express application, I am trying to send the contact form from godaddy relay server. locally it works fine. but after I hosted with godaddy server it's not working. my local code: ( working using gmail properties )
app.post("/send_mail", function (req, res) {
let { text } = req.body;
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 25,
secure: true,
auth: {
user: "xxxxxx#gmail.com",
pass: "xxxxxxxx"
}
});
let message = {
from: "from#email.com",
to: "xxxx#gmail.com",
subject: "Enquiry from Deane Project Management",
html: `
<hr />
<h1>Request for: ${text.option || "No title"}</h1>
<span>Name: ${text.username}</span><br/>
<span>Email: ${text.email}</span><br/>
<span>Phone: ${text.phone || "No phone"}</span><br/>
<span>Message:</span><br/>
<p>${text.message || "No message"}</p>
<hr />
`
}
transporter.sendMail(message, function (err, info) {
if (err) {
console.log(err);
} else {
console.log('sent', info);
}
});
res.send(200);
});
I am taken this reference,(https://in.godaddy.com/help/send-form-mail-using-an-smtp-relay-server-953#cpanel) relay server so updated my server app.js like this: But not works. I am not getting any error as well. from from end it's shows success message. But no email received yet.
app.post("/send_mail", function(req, res) {
let {text} = req.body;
const transporter = nodemailer.createTransport({
host: 'localhost',
port: 25,
secure: false
});
let message = {
from: "from#email.com",
to: "xxxxx#gmail.com",
subject: "Enquiry from Deane Project Management",
html: `
<hr />
<h1>Request for: ${text.option||"No title"}</h1>
<span>Name: ${text.username}</span><br/>
<span>Email: ${text.email}</span><br/>
<span>Phone: ${text.phone||"No phone"}</span><br/>
<span>Message:</span><br/>
<p>${text.message||"No message"}</p>
<hr />
`
}
transporter.sendMail(message, function(err, info) {
if (err) {
console.log(err);
} else {
console.log('sent',info);
}
});
res.send(200);
})

Sending PKPass via email using nodejs

I'm generating the pkpass successfully server-side and now I'm trying to send the pkpass via email. I'm using nodemailer to try and do this but when I try to open the pass after downloading it from the sent email I get this error The pass "Event.pkpass" could not be opened. The pass can be opened via my app and works fine. What am I doing wrong?
Pass Url: shoebox://card/Q03UycwVF9DPkMG6ytNw+DviZ6A=
Generating the PKPass:
try {
const examplePass = await createPass({
model: "./models/Event.pass",
certificates: {
wwdr: "./models/certs/wwdrc.pem",
signerCert: "./models/certs/signerCert.pem",
signerKey: {
keyFile: "./models/certs/signerKey.pem",
passphrase: "54321"
}
},
overrides: {
// keys to be added or overridden
serialNumber: serialNumber
}
});
examplePass.barcode("36478105430"); // Random value
examplePass.headerFields.push({
label : "EVENT",
key : "title",
value : title
});
examplePass.primaryFields.push({
key : "date",
label : "DATE",
value : date
});
examplePass.secondaryFields.push({
key : "location",
label : "LOCATION",
value : location
});
// Generate the stream, which gets returned through a Promise
const stream = examplePass.generate();
res.set({
"Content-Type": "application/vnd.apple.pkpass",
"Content-disposition": `attachment; filename=${passName}.pkpass`
});
stream.pipe(res);
Sending the email:
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: 'email#gmail.com',
pass: 'password'
}
});
let mailOptions = {
from: 'email#gmail.com',
to: userEmail,
subject: "You're on your way to ",
html: '<h1>Testing email</h1>',
attachments: [
{
filename: 'Event.pkpass',
contentType: 'application/vnd.apple.pkpass',
content: stream
}
]
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error.message);
}
console.log('success');
});

Can't send email with nodemailer and outlook

i try to send an email with nodemailer and outlook but after multi try and multiple forum i visited, i found nothing.
I try all the solution i've seen but nothing work. can you help me please
this is my code :
{
const path = require('path');
var message=fs.readFileSync(path.join(__dirname+'../../../asset/templateMail/mail.html')).toString();
message=message.replace('${user}', user.confirmation_code.toString());
var nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport(
{
//service :"Outlook365",
//pool:true,
host: 'SMTP.office365.com',
port: '587',
secure:false,
auth: { user: "it-factory-flex#outlook.fr", pass: process.env.NODEMAILLERPASS },
//secureConnection: false,
//requireTLS:true,
//tls: { ciphers: 'SSLv3' }
}
);
var mailOptions = {
name:"FlexOffice",
from: "it-factory-flex#outlook.com",
to: user.email,
subject: "FlexOffice: Code d'inscription",
html: message
}
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
all the commented part are my test
and i always got this:
Error: Connection timeout
at SMTPConnection._formatError (/home/romain/bred/flex-server/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at SMTPConnection._onError (/home/romain/bred/flex-server/node_modules/nodemailer/lib/smtp-connection/index.js:770:20)
at Timeout.<anonymous> (/home/romain/bred/flex-server/node_modules/nodemailer/lib/smtp-connection/index.js:235:22)
solved, due to my network who block the flux.

Resources