components_node/functions-email.js
/**
     * Function to send e-mail message.
     * @static
     * @param {object} _objEmailSendParameters 
     * @returns {object}
     * @example
     * SyncSystemNS.FunctionsEmail.emailSend({})
     */
Function to send e-mail message.
Function to send e - mail message .
static async emailSend(_objEmailSendParameters)
    {
        let objReturn = {returnStatus: false};
        let emailSendResult;
            try{ 
                let nodemailerTransporterParameters;
                nodemailerTransporterParameters = {
                    pool: true,
                    host: process.env.CONFIG_EMAIL_DEFAULT_HOST,
                    port: process.env.CONFIG_EMAIL_DEFAULT_PORT,
                    auth: {
                        user: process.env.CONFIG_EMAIL_DEFAULT_USERNAME,
                        pass: process.env.CONFIG_EMAIL_DEFAULT_PASSWORD
                    },
                    secure: false,
                    tls: {
                        rejectUnauthorized: false
                    } 
                };
                const transporter = nodemailer.createTransport(nodemailerTransporterParameters);
                emailSendResult = await transporter.sendMail({
                    from: _objEmailSendParameters._emailSenderName + "<" + _objEmailSendParameters._emailSender + ">",
                    to: _objEmailSendParameters._emailSenderRecipientName +  "<" + _objEmailSendParameters._emailSenderRecipient + ">",
                    replyTo: _objEmailSendParameters._emailReply,
                    subject: _objEmailSendParameters._emailSubject,
                    text: _objEmailSendParameters._emailBodyMessageText,
                    html: _objEmailSendParameters._emailBodyMessageHTML, 
                    encoding: "utf-8", 
                    priority: "normal" 
                });
                transporter.close();
                if(emailSendResult.accepted.length > 0)
                {
                    objReturn.returnStatus = true;
                }
            }catch(emailSendError){
                if(gSystemConfig.configDebug === true)
                {
                    console.log("emailSendError=", emailSendError);
                    console.error("emailSendError=", emailSendError);
                }
            }finally{
                return objReturn;
            }
    }
static async emailSend ( _objEmailSendParameters ) { let objReturn = { returnStatus : false } ; let emailSendResult ; try { let nodemailerTransporterParameters ; nodemailerTransporterParameters = { pool : true , host : process . env . CONFIG_EMAIL_DEFAULT_HOST , port : process . env . CONFIG_EMAIL_DEFAULT_PORT , auth : { user : process . env . CONFIG_EMAIL_DEFAULT_USERNAME , pass : process . env . CONFIG_EMAIL_DEFAULT_PASSWORD } , secure : false , tls : { rejectUnauthorized : false } } ; const transporter = nodemailer . createTransport ( nodemailerTransporterParameters ) ; emailSendResult = await transporter . sendMail ( { from : _objEmailSendParameters . _emailSenderName + "<" + _objEmailSendParameters . _emailSender + ">" , to : _objEmailSendParameters . _emailSenderRecipientName + "<" + _objEmailSendParameters . _emailSenderRecipient + ">" , replyTo : _objEmailSendParameters . _emailReply , subject : _objEmailSendParameters . _emailSubject , text : _objEmailSendParameters . _emailBodyMessageText , html : _objEmailSendParameters . _emailBodyMessageHTML , encoding : "utf-8" , priority : "normal" } ) ; transporter . close ( ) ; if ( emailSendResult . accepted . length > 0 ) { objReturn . returnStatus = true ; } } catch ( emailSendError ) { if ( gSystemConfig . configDebug === true ) { console . log ( "emailSendError=" , emailSendError ) ; console . error ( "emailSendError=" , emailSendError ) ; } } finally { return objReturn ; } }
Function to send e-mail message.
Function to send e - mail message .
/*
        _objEmailSendParameters: {
            _emailSender: "",
            _emailSenderName: "",
            _emailSenderRecipient: "",
            _emailSenderRecipientName: "",
            _emailReply: "",
            _emailCC:[
                {
                    email: "",
                    name: ""
                },
                {
                    email: "",
                    name: ""
                }
            ],
            _emailBCC:[
                {
                    email: "",
                    name: ""
                },
                {
                    email: "",
                    name: ""
                }
            ],
            _emailSubject: "",
            _emailBodyMessageText: "",
            _emailBodyMessageHTML: "",
            _emailSendType: "", //11 - nodemailer
            _emailFormat: "" //0 - text | 1 - HTML
        }
        */ //Variables. //---------------------- //---------------------- //Logic. //---------------------- //(async function(){ //async marks the block //Nodemailer. //Build parameters. //Also keep in mind this leaves you vulnerable to MITM attacks on SSL. ref: https://stackoverflow.com/questions/14262986/node-js-hostname-ip-doesnt-match-certificates-altnames/16311147#16311147 //Create transport. //Send mail. /*
                emailSendResult = await transporter.sendMail({
                    from: gSystemConfig.enableEmailSenderNameDefault + "<" + gSystemConfig.enableEmailSenderDefault + ">",
                    to: gSystemConfig.enableEmailRecipientNameDefault +  "<" + gSystemConfig.enableEmailRecipientDefault + ">",
                    replyTo: gSystemConfig.enableEmailSenderDefault,
                    subject: "testing e-mail sending",
                    text: _objEmailSendParameters._emailBodyMessageText,
                    html: _objEmailSendParameters._emailBodyMessageHTML, //research amp:
                    encoding: "utf-8", //hex | base64
                    priority: "normal" //high | normal | low
                    //dkim: //https://nodemailer.com/dkim/
                });*/ //working /*
                    cc: [
                        "foobar@example.com",
                        "Ноде Майлер <bar@example.com>"
                    ],
                    bcc: [
                        "foobar@example.com",
                        {
                            name: "Майлер, Ноде",
                            address: "foobar@example.com"
                        }
                    ],
                    */ //research amp: //hex | base64 //high | normal | low //dkim: //https://nodemailer.com/dkim/ //Success. /*
                emailSendResult= {
                    accepted: [ 'xx@xxx.com' ],
                    rejected: [],
                    envelopeTime: 38,
                    messageTime: 1027,
                    messageSize: 1434,
                    response: '250 2.0.0 Ok: queued as 0D52A540746',
                    envelope: {
                        from: 'yyy@yyy.com',
                        to: [ 'xx@xxx.com' ]
                    },
                    messageId: '<3b3ff07c-160e-8933-31b8-88f6fb689045@yyy@yyy.com>'
                }*/ //Debug. //console.log("emailSendResult=", emailSendResult); //})() //----------------------