【问题标题】:How to move to next line in nodeJS如何在nodeJS中移动到下一行
【发布时间】:2019-05-30 23:21:44
【问题描述】:

今天我刚开始使用 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}

【问题讨论】:

  • New Line in Node.js的可能重复
  • 是的,我试过了,但无法在这里实现。我是 nodejs 的新手
  • 你写\n或\r\n时发生了什么...结果是什么?
  • 什么都没有发生,但实际上开始出错,您引用的链接完全不同。就我而言,所有都是字符串,所以我不知道应该在哪里使用 + "\r\n"

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


【解决方案1】:

你能试试这个并分享输出吗...

 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'
}]

【讨论】:

  • 谢谢第一个实际上是断线但第二个不起作用你能告诉我如何在这里使用 URL 显示图像
  • 您需要在电子邮件中插入图片(作为链接)吗?
  • 否,但使用某些 URL 在电子邮件中显示图像,例如 const url ="image-link" 在 mailOption,text 中显示此内容
  • 对不起@Akber Iqbal 我只是检查了你的代码,但它没有显示图像,只是它像以前一样放置文本
  • 您刚刚插入了 mailOptions.html 部分...不是 mailOptions.text 部分,对吗?...因为 mailOptions.html 将发送一封电子邮件,您可以在其中包含图像... mailOptions。 text 只是发送一个文本电子邮件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多