Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

creating a custom function to use nodemailer to send email

require('dotenv').config();

//importing the module nodemailer
var nodemailer = require('nodemailer');

//importing smtp
var smtpTransport = require('nodemailer-smtp-transport');

var sendingEmail = {};

//method to send an email
sendingEmail = {
    sendEmail: async function(recipient, subject, message, cb){
        var transporter = nodemailer.createTransport(smtpTransport({
            host: process.env.SMTP_SERVER,
            port: process.env.SMTP_PORT,
            secure: false,
            auth: {
                user: `${process.env.SMTP_USERNAME}`,
                pass: `${process.env.SMTP_PASSWORD}`
            },
            tls: {
                rejectUnauthorized: false
            }
        }));

        var mailOptions = {
            from: process.env.SMTP_USERNAME,
            to: recipient,
            subject: subject,
            text: `From : ${recipient}

 ${message}`
        };

        await transporter.sendMail(mailOptions, (error, info) => {
            if(error){
                console.log(error);
            }else{
                console.log("Success: Email received from : ", recipient);
                console.log(info.response);
            }
        });
    }
}

module.exports = sendingEmail;
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert json to arraylist java 
Javascript :: javascript map callback function 
Javascript :: javascript Passing Function Value as Default Value 
Javascript :: javascript console log current directory 
Javascript :: define conastant js 
Javascript :: socket io stream 
Javascript :: javascript regular expression methods 
Javascript :: KeyboardDatePicker background color 
Javascript :: Function.prototype.apply.call(console[level], console, argsWithFormat); 
Javascript :: json api data fetch error 
Javascript :: what is the use of consrtructors in reactjs 
Javascript :: react copy array 
Python :: import keys selenium 
Python :: pyspark import col 
Python :: python today - 1 day 
Python :: how to install matplotlib in python 
Python :: simple flask hello world 
Python :: get hour python 
Python :: django admin no such table user 
Python :: python check if file exists 
Python :: pandas change column to a string 
Python :: The following packages have unmet dependencies: libnode72 : Conflicts: nodejs-legacy E: Broken packages 
Python :: mp4 get all images frame by frame python 
Python :: pandas replace null with 0 
Python :: split data into training, testing and validation set python 
Python :: create dictionary python from two lists 
Python :: unix to datetime python 
Python :: python everything after last slash 
Python :: plot to image python 
Python :: python delete contents of file 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =