Nodemailer 发送电子邮件缓慢/延迟

时间:2021-03-02 12:06:45

标签: email google-cloud-functions gmail nodemailer

我想知道是否有一种方法可以加快在 gmail 上使用 Nodemailer 发送电子邮件的速度。

我使用了标准的 nodemailer 文档,代码运行良好。我的问题是电子邮件和附件(使用用户输入的 pdfmake 创建)在大约 7-10 分钟后发送。有没有办法加快这个速度?这对用户体验真的很有帮助。

我应该提到需要 nodemailer 的函数是从应用程序调用的,并且是一个 Firebase 云函数。

以下是我的 firebase 云函数的代码:

exports.createCNDA = functions.https.onCall((data, context) => {
    // Authentication / user information is automatically added to the request.
const uid = context.auth.uid;
const email = context.auth.token.email 
const token = data.itemId;


admin.database().ref('users').child(`${uid}`).child('IA').child(`${token}`)
            .child('Project').once('value').then(function(snapshot) {
                const Project = snapshot.val();

                var docDefinition = {
                    content: [
                        {
                            text: '\n\nNON-DISCLOSURE AGREEMENT\n\n\n\n ',
                            style: 'header2'
                        },
                        {
                            text: 'BETWEEN \n\n\n' + `${Party1} ` + '\n\n\n\n and \n\n\n\n' + `${Party2}`,
                            style: 'header3',
                            pageBreak: 'after'
                        },
                        {style: 'bigger2',
                            text: [
                                'This Non-Disclosure Agreement is made this _______ day of _________________ 20____, by and between: \n\n',
                                {text:  `${Party1}`, style: 'header'},
                               ' ' + `${RC1}` + ' whose address is ' + `${Address1} ` + ' hereinafter referred to as the "Discloser." \n\n',
                                'and\n\n ',
                                {text: `${Party2}`, style: 'header'},
                                ' ' + `${RC2}` +' whose address is '+ `${Address2} ` + ' hereinafter referred to as the "Recipient." \n\n',
                                'Recipient and Discloser shall be referred collectively as the “Parties" and where the context requires, each, a “Party”)\n',
                                '\n',
                                {text: 'WHEREAS:\n ', style: 'header'}
                            ]
                        },
                        
                    {       style: 'bigger',
                            ol: [
                                'In consideration of the discussion between Parties about ' + `${Project} `  + ' (“Project”), the Recipient may be exposed to Discloser’s information (“Confidential Information”) which the Discloser, in the context of the Project , is to make available to the Recipient. \n\n',
                                'Parties acknowledge that it is of the utmost importance to the Discloser that the Confidential Information remains confidential and that its disclosure to any third-party  other than as permitted under the terms hereof may prejudice the Discloser’s operations and business; and \n\n',
                                'Parties  have agreed to set out their obligations regarding such Confidential Information under the following terms and conditions:\n\n'
                            ]
                        },
                        {text: 'NOW THEREFORE THE PARTIES HEREBY AGREE AS FOLLOWS: \n\n', style: 'header4'},
                        {text: '1. FOR THE PURPOSES OF THIS AGREEMENT: \n\n', style: 'header4'},
                        {
                            style: 'bigger',
                            italics: false,
                            text: [
                                {text: '"Affiliate" ', style: 'header4'},
                                'means, with respect to a Party, a company which controls it directly or indirectly, a company which it controls directly or indirectly, or a company which is controlled directly or indirectly by a third company which also controls that Party directly or indirectly.\n',
                                'An entity is deemed to “control” another if it owns directly or indirectly at least fifty percent (50%) of the shares entitled to vote at a general election of directors of such other entity.\n\n ',
                                
                                 {text: '"Confidential Information" ', style: 'header4'},
                                'means, shall mean all oral or written information, data and other material in whatever form including information in a document, electronic file or captured in any other way of representing or recording information which contains or is derived or copied from such information, relating to the Project or sponsors of the Project and their affiliates, or  relating to the activities of the Discloser and its affiliates, their interests and/or business, which is disclosed to the Recipient by the Discloser in connection with the Project, and also including any analyses, compilations and other material which contain or reflect such information, whether or not stated to be confidential, but excluding any information:\n\n',
                                'a. which was known to the Recipient prior to disclosure in the terms hereof; \n\n',
                                'b. which is or becomes public knowledge through no breach of the Recipient of the herein; and or \n\n',
                                'c. the Recipient lawfully receives without any such restrictions or obligations of confidentiality from a third party who in turn (to the best of the Recipient’s knowledge and belief) received such information legally and not in breach of any obligation of confidentiality.\n\n',
                                
                                {text: '"Project" ', style: 'header4'},
                                'means, ' + `${Project} `+ ' .\n\n',
                                {text: '"Parties " ', style: 'header4'},
                                'means, Recipient and the Discloser.\n\n',  
                                {text: '"Representatives " ', style: 'header4'},
                                'means, the affiliates, officers, employees, consultants, advisors, auditors, attorneys or agents of each  Party.\n\n',
                            ]
                        },
                                {text: 'Undertakings:\n\n', style: 'header4'},
                          {       style: 'bigger2',
                                    start: 2,
                            ol: [
                                'By virtue of the disclosure by the Discloser to the Recipient of the Confidential Information, the Recipient will become possessed of and have access to Discloser’s Confidential Information and accordingly the Recipient undertakes in favour of the Discloser that it shall ensure that its employees, representatives, agents, advisers and consultants shall: \n\n',
                                {       style: 'bigger2',
                                    type: 'lower-alpha',
                            ol: [
                                'Keep secret and confidential and not, without the written consent of the Discloser, disclose to any person (other than persons permitted herein, or as required by law, by any court, or pursuant to enquiry or investigation, by any governmental, or regulatory body which is lawfully entitled to require such disclosure), any Confidential Information that it may receive  as a result of such disclosure and its participation in and/or association with the Project.  In the event that the Discloser consents to the disclosure of Confidential Information, the Recipient shall take all the necessary steps to ensure that similar confidentiality obligations as contained herein, are imposed on the persons to whom the Confidential Information is to be disclosed, and the Recipient shall be responsible for any breach of confidentiality by such persons; \n\n',
                                'Not disclose to any third party (other than as permitted herein) the fact that the Discloser has approached the Recipient regarding the Project, or that discussions or negotiations are taking place between the parties, save with the consent of the Discloser (which consent shall not be unreasonably withheld), or to the extent required by law; and \n\n',
                                'Use the Confidential Information only towards the proposed Project\n\n'
                            ]
                        },
                        ]
                          },
                        
                            {       style: 'bigger2',
                                    start: 3,
                            ol: [
                                'The Recipient undertakes to ensure that disclosure of the Confidential Information is made to its  employees, representatives, agents, advisers and consultants only to the extent necessary for the purposes of assessing the Project, it being understood that those employees, representatives, agents, advisers and consultants shall be informed by Recipient of the confidential nature of such information and shall be directed to treat such information confidentially;  \n\n',
                                'The Recipient undertakes that  where it and/or any of its Representatives becomes legally compelled to disclose any of the Confidential Information regarding the proposed  Project, the Party shall, to the extent permitted by law, notify the Discloser so that it or the sponsors of the Project may seek a protective order or other appropriate remedy to stall disclosure of the Confidential information;\n\n',
                                'The Recipient undertakes to return to the Discloser within twenty-one (21) days of receipt of written demand from the Discloser, all documents or other materials containing Confidential Information, and expunge or delete all Confidential Information from all computer and other devices in its control, including all copies or reproductions thereof. Notwithstanding the foregoing, the Recipient will not be required to return or expunge documents or other materials containing Confidential Information to the extent that the Recipient is obliged by applicable laws and regulations to keep them and in which case the Recipient shall continue to protect and treat such information confidentially;  \n\n',
                                'This Agreement and the confidentiality undertakings contained herein shall continue for as long as the Confidential Information disclosed to the Recipient remains Confidential Information in terms hereof, but not later than one (2) years from the effective date of this Agreement; \n\n',
                                'The Discloser acknowledges that while the Recipient may rely on the Confidential Information for purposes of assessing the Project, the Recipient in accordance with its procedures may conduct its own due diligence in relation to the Project and make its own independent decision concerning the Project; \n\n',
                                'Nothing contained in this Agreement may be construed as binding or committing either of the Parties to negotiate or conclude any definitive agreement in connection with the Project; \n\n',
                                'The Recipient acknowledges and agree that neither Discloser nor any of its Representatives (i) may make any representation or warranty, express or implied, as to, or assume any responsibility for, the accuracy, reliability or completeness of any of the Confidential Information or any other information supplied by the Discloser or any of its Representatives or the assumptions upon which it is based; and (ii) shall be under any obligation to update or correct any inaccuracy in the Confidential Information or any other information supplied by the Discloser or any of its Representatives or be otherwise liable to the Recipient or any other person in respect of the Confidential Information or such information; \n\n',
                                'The Recipient acknowledges that damages may be inadequate compensation for any breach of this Agreement and the Recipient agrees that the Discloser shall be entitled to seek an injunction, specific performance, or similar remedy against any conduct or threatened conduct which is or would be a breach of this Agreement; \n\n',
                                'This Agreement constitutes the entire agreement between the Parties hereto relating to the subject matter hereof, and no terms or provisions of this Agreement shall be varied or modified by any prior or subsequent statement, conduct or act of any of the Parties except where  the Parties  amend this Agreement by written instruments specifically referred to and executed in the same manner as this Agreement, which instrument shall be signed by the duly authorised representatives of the Parties; \n\n',
                                'The interpretation, implementation, enforcement and termination of this Agreement shall be governed in accordance with the laws of the Federal republic of Nigeria, which shall, for all purposes of this Agreement be the governing law of this Agreement. Any dispute or difference arising out of or in connection with this Agreement which cannot be settled amicably between the Parties shall be settled by mediation within 15 working days. In the event that the above-mentioned mediation does not resolve the dispute, the dispute shall be settled by arbitration in accordance with the existing rules of the Lagos Multi-Door Court (LMDC) before an arbitrator, jointly appointed by Parties. The place and legal seat of arbitration will be Lagos, Nigeria and the language of the arbitration shall be English.  The resulting award shall be final and binding on the Parties and shall be in lieu of any other remedy; \n\n',
                                'For purposes of receiving any notice or communication under this Agreement, the Recipient and Discloser agree that all notices and correspondence be addressed to the addresses provided next to their names at the commencement of this Agreement ; \n\n',
                                'This Agreement may be executed in two (2) or more counterparts, each of which shall be deemed an original, but all of which together shall constitute the same Agreement. \n\n',
                            ]
                        },
                        
                        '\n\n For and on behalf of ' +  `${Party1} ` + ':  \n\n Signature: _________________________  \n\n Name: _________________________  \n\n Position: _________________________',
                    
                        '\n\n For and on behalf of ' +  `${Party2} ` + ':  \n\n Signature: _________________________  \n\n Name: _________________________  \n\n Position: _________________________' ,
                    ],
                    styles: {
                        header: {
                            fontSize: 18,
                            bold: true
                        },
                        header2: {
                            fontSize: 28,
                            bold: true,
                            alignment:"center"
                        },
                            header3: {
                            fontSize: 18,
                            bold: true,
                            alignment:"center"
                        },
                            header4: {
                            fontSize: 12,
                            bold: true,
                        },
                        header5: {
                            fontSize: 12,
                            bold: true,
                        },
                        bigger: {
                            fontSize: 12,
                            italics: true
                        },
                            bigger2: {
                            fontSize: 12,
                            
                        }
                    }
                    
                }

      var pdfDoc = printer.createPdfKitDocument(docDefinition);   
      let file_name = 'MPC. ' + `${token}` +  '.pdf';
    const myPdfFile = storage.bucket(BUCKET).file(file_name);
    pdfDoc.pipe(myPdfFile.createWriteStream())
    .on('finish', function (){
      
       
        const dest = email;
        const mailOptions = {
            from: 'My <xxxxxxxxxx@gmail.com>', 
            to: dest,
            subject: 'My Corporate NDA Doc: ' + `${token}`, 
            html: `<p style="font-size: 16px;">Dear Customer</p>
                <br />
                <p style="font-size: 16px;">Many Thanks for trusting us with your document. Please let us know if you require any clarifications. </p>
                <br />
                <p style="font-size: 16px;">Best Regards, </p>
                <br/>
                My Team`,
                attachments: [
                    {   
                        filename: 'MPC. ' + `${token}` +  '.pdf',
                        contentType: 'application/pdf',
                        content: myPdfFile.createReadStream()
                    }
                ]  
        };
  
        // returning result
        return transporter.sendMail(mailOptions);
  
    })
    .on('error', function(err){
      console.log('Error during the wirtestream operation in the new file' +  err);
     alert('Error: something goes wrong ! '+ err);
    });
    
    pdfDoc.end();
});

0 个答案:

没有答案
相关问题