1

Today I just started with firebase NodeJs authenciation trigger to send an welcome email when a user first time signUp. Here is an index.js file from official documents(modified)

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);
  });
}

But how I can move to next line in this line

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

I want to move to next line after

Welcome to ${APP_NAME}
Manik
  • 153
  • 4
  • 15
  • Possible duplicate of [New Line in Node.js](https://stackoverflow.com/questions/10384340/new-line-in-node-js) – Akber Iqbal Jan 04 '19 at 11:44
  • Ya I tried this but not able to implement here . I am new on nodejs – Manik Jan 04 '19 at 11:53
  • what happened when you wrote \n or \r\n... what was the result? – Akber Iqbal Jan 04 '19 at 11:54
  • Nothing is happening but start making error actually the link you refer is quite different . In my case all are string so I don't know where I should use + "\r\n" – Manik Jan 04 '19 at 11:58

1 Answers1

2

could you try this and share the output...

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

you'd have to insert an html option if you want to include a link to an image... the previous code (above) sent text-only emails

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

and

mailOptions.attachments = [{
            filename: 'angular.png',
            path: 'https://www.akberiqbal.com/logos/angular.png',
            cid: 'logo'
}]
Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70