Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Nodemailer Reuseable Code

import NodeMailer from 'nodemailer'
import emailConfig from '../../config/mail' // read email credentials from your config

class EmailSender {
    transport

    constructor() {
        this.transport = NodeMailer.createTransport({
            host: emailConfig.MAIL_HOST,
            port: emailConfig.MAIL_PORT,
            auth: {
                user: emailConfig.MAIL_USERNAME,
                pass: emailConfig.MAIL_PASSWORD,
            },
        })
    }

    async sendMessage(to, subject, text, html) {
        let mailOptions = {
            from: emailConfig.MAIL_FROM_ADDRESS,
            to,
            subject,
            text,
            html,
        }

        await this.transport.sendMail(mailOptions)
    }
}

export default new EmailSender()
Comment

Nodemailer Reuseable Code 1

router.get('/email', async (req, res) => {
    try {
        await EmailSender.sendMessage(
            'bijaya@bijaya.com',
            'Hello world',
            'test',
            '<h1>Test</h1>'
        )

        return res.status(200).send('Successfully sent email.')
    } catch (exception) {
        return res.status(500).send(exception.message)
    }
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js get message content 
Javascript :: string format javascript 
Javascript :: id on delete action javascript react 
Javascript :: Sending e-mail using Mandrill API 
Javascript :: data toggle modal and tooltip 
Javascript :: nested json example 
Javascript :: loop featured image react wordpress api 
Javascript :: javascript react store component as function 
Javascript :: discord.js v12 to v13 
Javascript :: jquery ui music player 
Javascript :: axios with load more 
Javascript :: code mirror get value from dom 
Javascript :: TextInputEditText click event 
Javascript :: How to find object length in vue 
Javascript :: cache blogposts for 24 hours react native 
Javascript :: joi for validation 
Javascript :: get size of json array online 
Javascript :: req.parms en react js 
Javascript :: add and remove multiple markers on google maps js 
Javascript :: Using the Unshift() Method to Reverse an Array 
Javascript :: Paginate array in JavaScript 
Javascript :: angular 8 input decorator Expected 2 arguments, but got 1. 
Javascript :: what is render in react native 
Javascript :: loader on map function in react js 
Javascript :: for loop display numbers 1 to 10 javascript 
Javascript :: make a circle in javascript 
Javascript :: find in array and return true or false react js 
Javascript :: javascript remove files name starts with 
Javascript :: void 0 js 
Javascript :: hide parent component when child component loaded 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =