如何在nodeJS中移至下一行

时间:2019-01-04 11:26:24

标签: node.js firebase npm google-cloud-functions nodemailer

今天,我刚开始使用Firebase NodeJs身份验证触发器,以便在用户首次注册时发送欢迎电子邮件。这是官方文档中的index.js文件(已修改)

const APP_NAME = 'Incredible India Tourism';


exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {

  const email = user.email; // The email of the user.
  const displayName = user.displayName; // The display name of the user.


  return sendWelcomeEmail(email, displayName);
});

exports.sendByeEmail = functions.auth.user().onDelete((user) => {
// [END onDeleteTrigger]
  const email = user.email;
  const displayName = user.displayName;

  return sendGoodbyeEmail(email, displayName);
});
// [END sendByeEmail]

// Sends a welcome email to the given user.
function sendWelcomeEmail(email, displayName) {
  const mailOptions = {
    from: `${APP_NAME} <noreply@firebase.com>`,
    to: email,
  };

  // The user subscribed to the newsletter.
  mailOptions.subject = `Welcome to ${APP_NAME}!`;
  mailOptions.text = `Hey ${displayName || ''}! Welcome to ${APP_NAME}. We hope you will enjoy our service.`;
  return mailTransport.sendMail(mailOptions).then(() => {
    return console.log('New welcome email sent to:', email);
  });
}

// Sends a goodbye email to the given user.
function sendGoodbyeEmail(email, displayName) {
  const mailOptions = {
    from: `${APP_NAME} <noreply@firebase.com>`,
    to: email,
  };

  // The user unsubscribed to the newsletter.
  mailOptions.subject = `Bye!`;
  mailOptions.text = `Hey ${displayName || ''}!, We confirm that we have deleted your ${APP_NAME} account.`;
  return mailTransport.sendMail(mailOptions).then(() => {
    return console.log('Account deletion confirmation email sent to:', email);
  });
}

但是我如何才能移至该行的下一行

 mailOptions.text = `Hey ${displayName || ''}! Welcome to ${APP_NAME}. We hope you will enjoy our service.`;

我想移到

之后的下一行
Welcome to ${APP_NAME}

1 个答案:

答案 0 :(得分:2)

您可以尝试一下并分享输出...

 mailOptions.text = `Hey ${displayName || ''}! Welcome to ${APP_NAME}. \n We hope you will enjoy our service.`;

如果要包含图像的链接,则必须插入 html选项 ...前面的代码(上面)发送了纯文本电子邮件

mailOptions.html = `
Hey ${displayName || ''}! Welcome to ${APP_NAME}.  
<br />
<img src="cid:logo">
<br/>
We hope you will enjoy our service. <br/> `;

mailOptions.attachments = [{
            filename: 'angular.png',
            path: 'https://www.akberiqbal.com/logos/angular.png',
            cid: 'logo'
}]