Git Product home page Git Product logo

Comments (8)

richleland avatar richleland commented on June 19, 2024

Hi @shahryargh I'm taking a look at this now with your example. I'll follow up shortly!

from nodemailer-sparkpost-transport.

richleland avatar richleland commented on June 19, 2024

OK took a look - you're missing the content key, which is where your subject, from, html, text, etc. go:

var nodemailer = require('nodemailer');
var sparkPostTransport = require('nodemailer-sparkpost-transport');
var htmlToText = require('nodemailer-html-to-text').htmlToText;

function getTransporter(){
  var options = {
    sparkPostApiKey: 'xxxxxxxxxxxxxxxxxx',
    options: {
      open_tracking: true,
      click_tracking: true,
      transactional: true
    }
  };
  return nodemailer.createTransport(sparkPostTransport( options ))
}

var transporter = getTransporter();   //above
var mailOptions = {
  recipients: [
    {
      address: {
        email: '[email protected]',
        name:  'Recipient Person'
      }
    }
  ],
  content: {
    from: '[email protected]', // sender address
    subject: 'nodemailer issue 5',
    html: '<p>testing</p>',
    text: 'YOU NEED TO ADD THIS MANUALLY' // https://www.npmjs.com/package/html-to-text
  },
  reply_to: '[email protected]',
};

transporter.use( 'compile', htmlToText() ); // this won't do anything
transporter.sendMail(mailOptions, function(error, info){
  if(error){
    console.log(`Error sending mail: ${error} and info: ${JSON.stringify(info)}`);in the error object
    return;
  }
  console.log(`Message sent: ${info.response}`);
});

Check out the API docs on our transmissions API - the options available there need to be passed in exactly like that in your mailOptions.

Also worth noting is that you'll have to generate the text content on your own - not with the nodemailer-html-to-text plugin. However that just uses html-to-text under the hood so you can invoke that manually and pass it to mailOptions.content.text.

from nodemailer-sparkpost-transport.

shahryargh avatar shahryargh commented on June 19, 2024

Nope, didn't work .. still getting the same error

      var transporter = getTransporter();       // see first post for def   

      var mailOptions = {

        "recipients": [
          { "address": {
              email:  "xxxxxgmail.com",
              name:   "xxxx",
          return_path: '[email protected]'
            }
          }
     ],

        "content": {
          "from": {
            "name":   "Sandy",
            "email":  '[email protected]'
          },
          "subject":  subject,
          "reply_to": "Info <[email protected]>",
          "headers": {
            "X-Customer-Campaign-ID": "test_campaign"
          },
          "text":     Html2Text.fromString( html, 
                          { wordwrap: 80, ignoreImage: true }),
          "html":     html
        }
      };

      transporter.sendMail( mailOptions
               , function( error, info ){
       ........//prints error
      });

Also, I used the other package you suggested and confirmed that it does convert HTML to text. I also tried removing headers object.

I wish the error was more descriptive.

from nodemailer-sparkpost-transport.

shahryargh avatar shahryargh commented on June 19, 2024

I tried using the exact same content and receipents object from curl command but still get the same error.

from nodemailer-sparkpost-transport.

shahryargh avatar shahryargh commented on June 19, 2024

Any updates on this issue?

from nodemailer-sparkpost-transport.

richleland avatar richleland commented on June 19, 2024

Hi @shahryargh there has to be something wrong with the file or the payload - the example I pasted above works for me every time. Do you want to put the entirety of your file in a gist and I can try to run that?

from nodemailer-sparkpost-transport.

shahryargh avatar shahryargh commented on June 19, 2024

there was a whitespace at the end of subject string );

I wish the error message was more self-explanatory

from nodemailer-sparkpost-transport.

dandv avatar dandv commented on June 19, 2024

Gotta say that error messages are still unhelpful, @SparkPost team.

I sent a request with recipients set to { email: ... } instead of { address: ... } and got just "Bad request". :-/

CC @jgzamora

from nodemailer-sparkpost-transport.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.