当前位置:网站首页>Nodejs send mail

Nodejs send mail

2022-06-11 02:16:00 KjPrime

Turn on POP3/SMTP service

  • Here are the QQ Mailbox is an example , Other e-mail addresses are Baidu
    POP3/SMTP

nodejs Code

  • install nodemailer rely on
npm install nodemailer
  • Code
/** * @author kjprime * @description  Send E-mail  */

const nodemailer   = require("nodemailer")

const config = {
    
    host: 'smtp.qq.com',   //  use QQ Just use this. , If other mailboxes , It needs to be replaced 
    port: 465,            //  port 
    auth: {
    
        user: '[email protected]', //  account number 
        pass: 'password'  // Authorization code or password 
    },
    secure: true
}

const server = nodemailer.createTransport(config)

const mail = {
    
    from: '[email protected]',
    to: '[email protected]',
    //text: ' I'm a test file ', 
    html: "<h1> I'm the headline </h1> <div> I am content. </div>", 
    subject: " Mailbox validation "          // Email title 
}

const Callback = function(err, msg) {
    
    // Callback function 
    if (err) {
    
        console.log(" fail in send ")
    }
    else{
    
        console.log(" Send successfully ")
        console.log(msg)
    }
}

// Start sending mail 
server.sendMail(mail, Callback)
原网站

版权声明
本文为[KjPrime]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020615478908.html