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 :: JSON stringify method - the optional parameters 
Javascript :: get current user moralis web3 login 
Javascript :: find invalid json files in directory 
Javascript :: node parse markdown files with frontmatter 
Javascript :: Your task is to take every letter and its index and form a string out of them. javascript 
Javascript :: best browser for programmers 
Javascript :: Flutter retrieve data from Json url 
Javascript :: GET_FORM-VALUE 
Javascript :: jwt sign options 
Javascript :: rnpm react-images-uploading 
Javascript :: javascript const scope = await angular.element(document.body).scope(); 
Javascript :: How to create an array containing 1...N 
Javascript :: 9.4.1.2. Loop Condition&para; 
Javascript :: Difference b/w AddEventListener and Attach Event 
Javascript :: nyaapi node 
Javascript :: javascript condition based on table cell value 
Javascript :: how to use window.alert in javascript 
Javascript :: js set to array casting 
Javascript :: online md5 decrypt 
Javascript :: Error: listen EACCES: permission denied 5000; 
Javascript :: Allowed Blocks in Nested Blocks Component Wordpress 
Javascript :: hover over class apply to subclass 
Javascript :: Node Red to their W1HQ station 
Javascript :: telegram web app js 
Javascript :: how is react different from normal js 
Javascript :: why is table.current.row.length not working 
Javascript :: {"javascript error: Invalid or unexpected token c# selenium 
Javascript :: for loop shothand in js 
Javascript :: filter list of array if not true return default array 
Javascript :: discord.js anonymous channel 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =