<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                --- title: 'node如何發生郵件,nodemailer' date: 2021-08-10 15:35:00 --- ![](https://img-blog.csdnimg.cn/20210810152919473.png?x-oss-processimage/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3h1dG9uZ2Jhbw,size_16,color_FFFFFF,t_70) ```javascript const nodemailer = require("nodemailer") let transporter const emailInit = async () => { // Generate test SMTP service account from ethereal.email // Only needed if you don't have a real mail account for testing let testAccount = await nodemailer.createTestAccount(); // create reusable transporter object using the default SMTP transport transporter = nodemailer.createTransport({ host: 'smtp.sina.cn', // service: 'qq', // port: 465, //secure: false, // true for 465, false for other ports secureConnection: true, // 使用了 SSL auth: { user: '136xxxxx@sina.cn', // generated ethereal user pass: '密碼' // generated ethereal password } }); } emailInit() //發送郵件 // async..await is not allowed in global scope, must use a wrapper const sendEmail = async (dataObj) => { const { path, username, errorTitle, detail, browser } = dataObj // send mail with defined transport object let info = await transporter.sendMail({ from: '<13642061747@sina.cn>', // sender address to: '1183391880@qq.com', //'1183391880@qq.com', // list of receivers subject: "知了好學錯誤報告", // Subject line html: ` <div> <div> <span>路徑:</span> <a href="http://zlhx.gongzuoshouji.cn/#${path}">${path}</a> </div> <div> <span>用戶名:</span> <span>${username}</span> </div> <div> <span>錯誤標題:</span> <span>${errorTitle}</span> </div> <div> <span>錯誤詳情:</span> <div style="white-space: pre-wrap">${detail}</div> </div> <div> <span>發生時間:</span> <span>${Date()}</span> </div> <div> <span>瀏覽器型號:</span> <span>${browser}</span> </div> </div>`// html body }); console.log("Message sent: %s", info.messageId); // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com> // Preview only available when sending through an Ethereal account console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... } module.exports = { //發送郵件 sendEmail, } ``` 開發接口,并把接口部署到阿里云上: ```javascript //發送郵件的接口 const dataEmail = async (req, res) => { const emailData = req.body await sendEmail({ ...emailData }).catch((err) => { console.log(err) }) res.send({ state: 1, data: emailData, message: '成功', }) } ``` 在其他node項目中調用阿里云的接口即可發郵件: 例如項目托管在([https://glitch.com/](https://glitch.com/)),這是一個國外的服務器,無法使用國內的郵箱直接發郵件,但是可以調用阿里云上的接口發郵件! ```javascript const axios = require('axios') //調用阿里云服務器上的發送郵件的接口 const emailPost = (emailData) => { axios .post('http://xxx:81/api/log/email', { ...emailData }) .then((res) => { console.log(`statusCode: ${res.statusCode}`) console.log(res) }) .catch((error) => { console.error(error) }) } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看