簡體   English   中英

根據要求發送 email 模板?

[英]Sending an email template on request?

如何選擇發送 email 的模板?
例如,我收到一個請求: reset_password 但我也有注冊( signup )。
我如何根據要求發送我需要的信件?
我想http://localhost:3000/sendmail?apiKey=test&type=reset_password

重置密碼: http://localhost:3000/sendmail?apiKey=test&type=reset_password
注冊: http://localhost:3000/sendmail?apiKey=test&type=signup
如果是注冊,注冊或密碼重置信
我該如何處理? 請求發送您需要的模板

const transporter = require("./transporter");
const ejs = require('ejs')
const path = require('path')


const mailer = async (type, to) => {
      what handler?
     const reset_password = path.join(__dirname, "../reset_password.ejs"),
     const signup = path.join(__dirname, "../signup.ejs")

    const data = await ejs.renderFile(reset_password,signup { to });


    const mainOptions = {
      from: 'test', 
      to: to,
      text: "Hello world?",
      subject: 'dw', 
      html: data
    };

    return transporter.sendMail(mainOptions) 
  };


module.exports = mailer;  

我該如何做到這一點:如果出現“reset_password”請求,則發送具有不同 email 模板的 email,如果是“注冊”,則發送具有不同模板的 email。 在類型請求中出現 reset_password 或注冊我不明白如何制作它,以便每個請求都有不同的 email 模板 ps:不同的類型。 和不同的字母模板

首先 - 修復您的郵件代碼

const mailer = async (type, to) => {
     const template = path.join(__dirname, `../${type}.ejs`)

    const data = await ejs.renderFile(template, { to });


    const mainOptions = {
      from: 'test', 
      to: to,
      text: "Hello world?",
      subject: 'dw', 
      html: data
    };

    return transporter.sendMail(mainOptions) 
  };

然后,確保將類型參數(第一個)發送到郵件 function

const { apiKey, type } = req.query
const email = '...' // todo: grab user email
mailer(type, email)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM