Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Nodemailer #Reuseable #Code
ADD COMMENT
Topic
Name
1+7 =