0

I just started with NodeJs so I don't know how to show images in NodeJs. I have referred my all code and the problem which I am facing.

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

  const email = user.email; // The email of the user.
  const displayName = user.displayName;  //The name of user 
  const image = user.photoURL;   // The image url of user
  // [END eventAttributes]

  return sendWelcomeEmail(email, displayName, image);
});

function sendWelcomeEmail(email, displayName , image) {
  const mailOptions = {
    from: `${APP_NAME} <noreply@firebase.com>`,
    to: email,
  };


mailOptions.subject = `Welcome to ${APP_NAME}!`;


    mailOptions.html = `
Hey ${name || ''}! Welcome to ${APP_NAME}.  
<br />
<img src="image">
<br/>
We hope you will enjoy our service. <br/> `;
  return mailTransport.sendMail(mailOptions).then(() => {
    return console.log('New welcome email sent to:', email);
  });
}

Here the image is not shown in html so how I can pass the image variable which contains the image url in below code

<img src="image">
Manik
  • 153
  • 4
  • 15
  • NodeJS is server side language. Images are usually displayed on the client or when doing server side rendering using template engine like ejs. I haven't read your question, but it should display image url, the image url should be used to load image – Alwaysblue Jan 14 '19 at 10:36
  • @NoobieSatan exactly I just want to load image using image url . Basically I copied the code from firebase welcome email and I wanted to show the image but I don't know what's wrong that I am getting negative points on my questions – Manik Jan 14 '19 at 10:41
  • I didn't marked this question Negative/downvoted. Either way, this will `${image}Hey ${displayName || ''}! Welcome to ${APP_NAME}. \n\n We hope you will enjoy our service.`;` becomes something like this when you send it.. `http://somedomain/imageURl.jpghey Manik Welcome to AppName. We hope you will enjoy our service` – Alwaysblue Jan 14 '19 at 10:46
  • Yep @NoobieSatan this is the output which is coming but instead of url how I can load image here. I don't have any clue for that. If you can help me it will be very helpful to me – Manik Jan 14 '19 at 10:48
  • Possible duplicate of [How to attach file to an email with nodemailer](https://stackoverflow.com/questions/21934667/how-to-attach-file-to-an-email-with-nodemailer) – Alwaysblue Jan 14 '19 at 10:51
  • @NoobieSatan I have updated my question please check it I am got stuck with this problem. – Manik Jan 16 '19 at 19:48

2 Answers2

1

Emails can be text, or they can contain HTML. The same HTML that a webpage is made of, which can contain images using the <img src="{url here}"> tags. So you should be using that tag in your email instead of just outputting the image URL. (You may also need to set the email's Content-type header to text/html to make it display properly.)

IceMetalPunk
  • 5,476
  • 3
  • 19
  • 26
  • Thanks for your help and with the help of html I just got some ideas to display image but by using html I got stuck with the problem which I updated please check it and help . – Manik Jan 16 '19 at 19:46
-1

You have to define image as: (not tested)

const image = <img src=${user.photoURL}/>
XRP DEV
  • 32
  • 3