From 624ba95792a7fa087b8e3eae66f8b3bdb8e79af9 Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Mon, 5 Aug 2024 14:31:55 +0530 Subject: [PATCH] fix: connection refused while sending mail --- .../parsefunction/sendMailGmailProvider.js | 17 ++++++----------- .../cloud/parsefunction/sendMailv3.js | 18 ++++++------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js b/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js index 36648c61c..0a826f701 100644 --- a/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js +++ b/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js @@ -43,17 +43,12 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => { response.on('end', () => resolve('success')); }); } else { - if (publicUrl.protocol === 'http:') { - http.get(url, async function (response) { - response.pipe(Pdf); - response.on('end', () => resolve('success')); - }); - } else { - https.get(url, async function (response) { - response.pipe(Pdf); - response.on('end', () => resolve('success')); - }); - } + const path = new URL(url)?.pathname; + const localurl = 'http://localhost:8080' + path; + http.get(localurl, async function (response) { + response.pipe(Pdf); + response.on('end', () => resolve('success')); + }); } }); }; diff --git a/apps/OpenSignServer/cloud/parsefunction/sendMailv3.js b/apps/OpenSignServer/cloud/parsefunction/sendMailv3.js index 65426f29c..eb23be4e4 100644 --- a/apps/OpenSignServer/cloud/parsefunction/sendMailv3.js +++ b/apps/OpenSignServer/cloud/parsefunction/sendMailv3.js @@ -7,7 +7,6 @@ import { smtpenable, smtpsecure, updateMailCount, useLocal } from '../../Utils.j import sendMailGmailProvider from './sendMailGmailProvider.js'; import { createTransport } from 'nodemailer'; async function sendMailProvider(req) { - const publicUrl = new URL(process.env.SERVER_URL); const mailgunApiKey = process.env.MAILGUN_API_KEY; try { let transporterSMTP; @@ -40,17 +39,12 @@ async function sendMailProvider(req) { response.on('end', () => resolve('success')); }); } else { - if (publicUrl.protocol === 'http:') { - http.get(req.params.url, async function (response) { - response.pipe(Pdf); - response.on('end', () => resolve('success')); - }); - } else { - https.get(req.params.url, async function (response) { - response.pipe(Pdf); - response.on('end', () => resolve('success')); - }); - } + const path = new URL(req.params.url)?.pathname; + const localurl = 'http://localhost:8080' + path; + http.get(localurl, async function (response) { + response.pipe(Pdf); + response.on('end', () => resolve('success')); + }); } }); };