Search code examples
node.jsemailhtml-emailsparkpost

HTML email a tag


I want to write html email with node.js app. Email is sent successfully. When I log text, it shows me something like this

<html><body><h1>Hi John!</h1><p>Jack just shared graph with you</p><p><a href='https://some.url.here/blablabla'>View here</a></p></body></html>

When I open this email with google inbox, it shows me html well, but a tag have no href attribute, so I cant go to given url from email. I am using sparkpost for email.

Can anyone tell me why it happens ?


Solution

  • You might want to try using double quotes for your href. I was able to get it to work using the code sample from developers.sparkpost.com

    var key = '<YOUR API KEY>'
    , SparkPost = require('sparkpost')
    , sparky = new SparkPost(key);
    
    sparky.transmissions.send({
      transmissionBody: {
        content: {
          from: 'testing@sparkpostbox.com',
          subject: 'Oh hey!',
          html:'<html><body><h1>Hi John!</h1><p>Jack just shared graph with you</p><p><a href="https://some.url.here/blablabla">View here</a></p></body></html>'
        },
        recipients: [
          {address: 'developers+stackoverflow@sparkpost.com'}
        ]
      }
    }, function(err, res) {
      if (err) {
        console.log('Whoops! Something went wrong');
        console.log(err);
      } else {
        console.log('Woohoo! You just sent your first mailing!');
      }
    });