mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-20 14:42:37 +02:00
v2.12.0
feat: create duplicate template functionality feat: add support of csv and xlsx for bulk contacts import feat: add info text for forms and dashboard button feat: implement functionality to delete a PDF page while editing the document feat: show completed documents in which signers included but not owner in completed reports feat: add delete folder button in opensign drive feat: introduce Bcc email support for sending completed documents feat: allow merging multiple pdf while drafting document and template feat: add 'My Initials' tab for auto-signing in request-sign flow feat: add support for redirect URL to navigate after document completion feat: introduce privacy policy and digital signature terms before signing documents. feat: add feature to allow adding new pages to existing document feat: add save signature, initials, stamp functionality in sign pad for logged in user feat: add preferences menu feat: add save custom email template, notifyonsignature, set timezone, allow signature types in preferences feat: secure local url feat: implement Italian language translation feat: implement German language translation feat: update menu name from report to documents and shift contactbook in main menu feat: provide edit contact functionality fix: unable to delete folder when all its documents are deleted fix: fields.push is not function fix: document loading issue in opensign drive fix: adjust the guest signature flow to display the document in full screen, eliminating any blank space which is displayed below the place holder in mobile view fix: resolve issue of instance of pdfdict or pdfstream but got undefined build(deps): update dependencies refactor: change note text from add contact form
This commit is contained in:
@@ -2,8 +2,6 @@ import axios from 'axios';
|
||||
import { google } from 'googleapis';
|
||||
import fs from 'node:fs';
|
||||
import https from 'https';
|
||||
import http from 'http';
|
||||
import { useLocal } from '../../Utils.js';
|
||||
const clientId = process.env.GOOGLE_CLIENT_ID;
|
||||
const clientSecret = process.env.GOOGLE_CLIENT_SECRET;
|
||||
// Function to create a Gmail client
|
||||
@@ -27,10 +25,24 @@ const refreshAccessToken = async refreshToken => {
|
||||
};
|
||||
|
||||
// Function to create a raw email message
|
||||
const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
const makeEmail = async (
|
||||
to,
|
||||
from,
|
||||
subject,
|
||||
html,
|
||||
url,
|
||||
pdfName,
|
||||
bcc,
|
||||
filename,
|
||||
certificatePath,
|
||||
replyto
|
||||
) => {
|
||||
const publicUrl = new URL(process.env.SERVER_URL);
|
||||
const htmlContent = html;
|
||||
const boundary = 'boundary_' + Date.now().toString(16);
|
||||
const bccHeader = bcc && bcc.length > 0 ? `BCC: ${bcc.join(',')}\n` : ''; // Construct BCC header if provided
|
||||
const replyToHeader = replyto ? `Reply-To: ${replyto}\n` : ''; // Construct Reply-To header if provided
|
||||
|
||||
let str;
|
||||
if (url) {
|
||||
let attachments;
|
||||
@@ -39,18 +51,24 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const isSecure =
|
||||
new URL(url)?.protocol === 'https:' && new URL(url)?.hostname !== 'localhost';
|
||||
if (useLocal !== 'true' || isSecure) {
|
||||
if (isSecure) {
|
||||
https.get(url, async function (response) {
|
||||
response.pipe(Pdf);
|
||||
response.on('end', () => resolve('success'));
|
||||
});
|
||||
} else {
|
||||
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'));
|
||||
});
|
||||
const httpsAgent = new https.Agent({ rejectUnauthorized: false }); // Disable SSL validation
|
||||
axios
|
||||
.get(url, { responseType: 'stream', httpsAgent })
|
||||
.then(response => {
|
||||
response.data.pipe(Pdf);
|
||||
Pdf.on('finish', () => resolve('success'));
|
||||
Pdf.on('error', () => resolve('error'));
|
||||
})
|
||||
.catch(e => {
|
||||
console.log('error', e.message);
|
||||
resolve('error');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -58,7 +76,7 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
const ress = await writeToLocalDisk();
|
||||
if (ress) {
|
||||
const file = {
|
||||
filename: `${pdfName}.pdf` || 'exported.pdf',
|
||||
filename: filename || `${pdfName}.pdf` || 'exported.pdf',
|
||||
type: 'application/pdf',
|
||||
path: Pdf.path,
|
||||
};
|
||||
@@ -68,7 +86,7 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
const certificate = {
|
||||
filename: 'certificate.pdf',
|
||||
type: 'application/pdf',
|
||||
path: './exports/certificate.pdf',
|
||||
path: certificatePath || './exports/certificate.pdf',
|
||||
};
|
||||
if (fs.existsSync(certificate.path)) {
|
||||
attachments = [file, certificate];
|
||||
@@ -99,6 +117,8 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
'MIME-Version: 1.0\n',
|
||||
`To: ${to}\n`,
|
||||
`From: ${from}\n`,
|
||||
bccHeader,
|
||||
replyToHeader,
|
||||
`Subject: ${subject}\n\n`,
|
||||
'--' + boundary + '\n',
|
||||
'Content-Type: text/html; charset="UTF-8"\n',
|
||||
@@ -114,6 +134,8 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
'MIME-Version: 1.0\n',
|
||||
`To: ${to}\n`,
|
||||
`From: ${from}\n`,
|
||||
bccHeader,
|
||||
replyToHeader,
|
||||
`Subject: ${subject}\n\n`,
|
||||
'--' + boundary + '\n',
|
||||
'Content-Type: text/html; charset="UTF-8"\n',
|
||||
@@ -127,7 +149,8 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
|
||||
return encodedMail;
|
||||
};
|
||||
export default async function sendMailGmailProvider(_extRes, template) {
|
||||
const { sender, receiver, subject, html, url, pdfName } = template;
|
||||
const { sender, receiver, subject, html, url, pdfName, bcc, filename, certificatePath, replyto } =
|
||||
template;
|
||||
|
||||
if (_extRes) {
|
||||
const refresh_token = _extRes.google_refresh_token;
|
||||
@@ -138,21 +161,30 @@ export default async function sendMailGmailProvider(_extRes, template) {
|
||||
// Construct email message
|
||||
const from = sender || _extRes.Email || 'me';
|
||||
const to = receiver;
|
||||
const email = await makeEmail(to, from, subject, html, url, pdfName);
|
||||
const email = await makeEmail(
|
||||
to,
|
||||
from,
|
||||
subject,
|
||||
html,
|
||||
url,
|
||||
pdfName,
|
||||
bcc,
|
||||
filename,
|
||||
certificatePath,
|
||||
replyto
|
||||
);
|
||||
// Update Gmail client with new access token
|
||||
const newGmail = createGmailClient(access_token);
|
||||
// sending email with new client
|
||||
const response = await newGmail.users.messages.send({
|
||||
userId: 'me',
|
||||
requestBody: {
|
||||
raw: email,
|
||||
},
|
||||
requestBody: { raw: email },
|
||||
});
|
||||
console.log('gmail provider res: ', response?.status);
|
||||
const certificatePath = './exports/certificate.pdf';
|
||||
if (fs.existsSync(certificatePath)) {
|
||||
const certificatepath = certificatePath || './exports/certificate.pdf';
|
||||
if (fs.existsSync(certificatepath)) {
|
||||
try {
|
||||
fs.unlinkSync(certificatePath);
|
||||
fs.unlinkSync(certificatepath);
|
||||
} catch (err) {
|
||||
console.log('Err in unlink certificate sendmailgmail provider');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user