mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-20 06:35:54 +02:00
Merge pull request #836 from OpenSignLabs/fix_smtp
Fix: smtp is not working
This commit is contained in:
@@ -247,3 +247,6 @@ export function sanitizeFileName(fileName) {
|
||||
}
|
||||
|
||||
export const useLocal = process.env.USE_LOCAL ? process.env.USE_LOCAL.toLowerCase() : 'false';
|
||||
export const smtpsecure = process.env.SMTP_PORT && process.env.SMTP_PORT !== '465' ? false : true;
|
||||
export const smtpenable =
|
||||
process.env.SMTP_ENABLE && process.env.SMTP_ENABLE.toLowerCase() === 'true' ? true : false;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { updateMailCount } from '../../Utils.js';
|
||||
import { smtpenable, updateMailCount } from '../../Utils.js';
|
||||
async function getDocument(docId) {
|
||||
try {
|
||||
const query = new Parse.Query('contracts_Document');
|
||||
@@ -25,9 +25,7 @@ async function sendMailOTPv1(request) {
|
||||
|
||||
if (email) {
|
||||
const recipient = request.params.email;
|
||||
const mailsender = process.env.SMTP_ENABLE
|
||||
? process.env.SMTP_USER_EMAIL
|
||||
: process.env.MAILGUN_SENDER;
|
||||
const mailsender = smtpenable ? process.env.SMTP_USER_EMAIL : process.env.MAILGUN_SENDER;
|
||||
try {
|
||||
await Parse.Cloud.sendEmail({
|
||||
from: 'Opensign™' + ' <' + mailsender + '>',
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
||||
import https from 'https';
|
||||
import formData from 'form-data';
|
||||
import Mailgun from 'mailgun.js';
|
||||
import { updateMailCount } from '../../Utils.js';
|
||||
import { smtpenable, smtpsecure, updateMailCount } from '../../Utils.js';
|
||||
import sendMailGmailProvider from './sendMailGmailProvider.js';
|
||||
import { createTransport } from 'nodemailer';
|
||||
async function sendMailProvider(req) {
|
||||
@@ -10,11 +10,11 @@ async function sendMailProvider(req) {
|
||||
let transporterSMTP;
|
||||
let mailgunClient;
|
||||
let mailgunDomain;
|
||||
if (process.env.SMTP_ENABLE) {
|
||||
if (smtpenable) {
|
||||
transporterSMTP = createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: process.env.SMTP_PORT || 465,
|
||||
secure: process.env.SMTP_SECURE || true,
|
||||
secure: smtpsecure,
|
||||
auth: {
|
||||
user: process.env.SMTP_USER_EMAIL,
|
||||
pass: process.env.SMTP_PASS,
|
||||
@@ -54,8 +54,8 @@ async function sendMailProvider(req) {
|
||||
const pdfName = req.params.pdfName && `${req.params.pdfName}.pdf`;
|
||||
const file = {
|
||||
filename: pdfName || 'exported.pdf',
|
||||
content: process.env.SMTP_ENABLE ? PdfBuffer : undefined, //fs.readFileSync('./exports/exported_file_1223.pdf'),
|
||||
data: process.env.SMTP_ENABLE ? undefined : PdfBuffer,
|
||||
content: smtpenable ? PdfBuffer : undefined, //fs.readFileSync('./exports/exported_file_1223.pdf'),
|
||||
data: smtpenable ? undefined : PdfBuffer,
|
||||
};
|
||||
|
||||
let attachment;
|
||||
@@ -64,8 +64,8 @@ async function sendMailProvider(req) {
|
||||
const certificateBuffer = fs.readFileSync('./exports/certificate.pdf');
|
||||
const certificate = {
|
||||
filename: 'certificate.pdf',
|
||||
content: process.env.SMTP_ENABLE ? certificateBuffer : undefined, //fs.readFileSync('./exports/exported_file_1223.pdf'),
|
||||
data: process.env.SMTP_ENABLE ? undefined : certificateBuffer,
|
||||
content: smtpenable ? certificateBuffer : undefined, //fs.readFileSync('./exports/exported_file_1223.pdf'),
|
||||
data: smtpenable ? undefined : certificateBuffer,
|
||||
};
|
||||
attachment = [file, certificate];
|
||||
} catch (err) {
|
||||
@@ -73,9 +73,7 @@ async function sendMailProvider(req) {
|
||||
console.log('Err in read certificate sendmailv3', err);
|
||||
}
|
||||
const from = req.params.from || '';
|
||||
const mailsender = process.env.SMTP_ENABLE
|
||||
? process.env.SMTP_USER_EMAIL
|
||||
: process.env.MAILGUN_SENDER;
|
||||
const mailsender = smtpenable ? process.env.SMTP_USER_EMAIL : process.env.MAILGUN_SENDER;
|
||||
|
||||
const messageParams = {
|
||||
from: from + ' <' + mailsender + '>',
|
||||
@@ -83,8 +81,8 @@ async function sendMailProvider(req) {
|
||||
subject: req.params.subject,
|
||||
text: req.params.text || 'mail',
|
||||
html: req.params.html || '',
|
||||
attachments: process.env.SMTP_ENABLE ? attachment : undefined,
|
||||
attachment: process.env.SMTP_ENABLE ? undefined : attachment,
|
||||
attachments: smtpenable ? attachment : undefined,
|
||||
attachment: smtpenable ? undefined : attachment,
|
||||
};
|
||||
if (transporterSMTP) {
|
||||
const res = await transporterSMTP.sendMail(messageParams);
|
||||
@@ -120,9 +118,7 @@ async function sendMailProvider(req) {
|
||||
}
|
||||
} else {
|
||||
const from = req.params.from || '';
|
||||
const mailsender = process.env.SMTP_ENABLE
|
||||
? process.env.SMTP_USER_EMAIL
|
||||
: process.env.MAILGUN_SENDER;
|
||||
const mailsender = smtpenable ? process.env.SMTP_USER_EMAIL : process.env.MAILGUN_SENDER;
|
||||
|
||||
const messageParams = {
|
||||
from: from + ' <' + mailsender + '>',
|
||||
|
||||
@@ -17,7 +17,7 @@ import { exec } from 'child_process';
|
||||
import { createTransport } from 'nodemailer';
|
||||
import { app as v1 } from './cloud/customRoute/v1/apiV1.js';
|
||||
import { PostHog } from 'posthog-node';
|
||||
import { useLocal } from './Utils.js';
|
||||
import { smtpenable, smtpsecure, useLocal } from './Utils.js';
|
||||
import { SSOAuth } from './auth/authadapter.js';
|
||||
let fsAdapter;
|
||||
if (useLocal !== 'true') {
|
||||
@@ -54,12 +54,12 @@ let transporterMail;
|
||||
let mailgunClient;
|
||||
let mailgunDomain;
|
||||
let isMailAdapter = false;
|
||||
if (process.env.SMTP_ENABLE) {
|
||||
if (smtpenable) {
|
||||
try {
|
||||
transporterMail = createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: process.env.SMTP_PORT || 465,
|
||||
secure: process.env.SMTP_SECURE || true,
|
||||
secure: smtpsecure,
|
||||
auth: {
|
||||
user: process.env.SMTP_USER_EMAIL,
|
||||
pass: process.env.SMTP_PASS,
|
||||
@@ -85,9 +85,7 @@ if (process.env.SMTP_ENABLE) {
|
||||
console.log('Please provide valid Mailgun credentials');
|
||||
}
|
||||
}
|
||||
const mailsender = process.env.SMTP_ENABLE
|
||||
? process.env.SMTP_USER_EMAIL
|
||||
: process.env.MAILGUN_SENDER;
|
||||
const mailsender = smtpenable ? process.env.SMTP_USER_EMAIL : process.env.MAILGUN_SENDER;
|
||||
export const config = {
|
||||
databaseURI:
|
||||
process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
|
||||
|
||||
Reference in New Issue
Block a user