Comments (8)
Hi @shahryargh I'm taking a look at this now with your example. I'll follow up shortly!
from nodemailer-sparkpost-transport.
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.
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.
I tried using the exact same content and receipents object from curl command but still get the same error.
from nodemailer-sparkpost-transport.
Any updates on this issue?
from nodemailer-sparkpost-transport.
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.
there was a whitespace at the end of subject string );
I wish the error message was more self-explanatory
from nodemailer-sparkpost-transport.
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)
- From in object issue HOT 2
- Allow for substitution_data on individual recipient level HOT 1
- Update release scripts and documentation HOT 1
- Refactor/simplify to use mailcomposer
- Template support HOT 1
- how to fix error SparkPostError: Bad Request HOT 1
- anything we had to fix to use the europe endpoint? HOT 8
- Dev dependencies need updating HOT 1
- High security warning - need to update lodash
- Support X-MSYS-API header
- This module shouldn't enforce the use of dotenv HOT 9
- Please update dependencies
- Incompatible w/nodemailer API? HOT 2
- Add cc/bcc support HOT 3
- Support attachments HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodemailer-sparkpost-transport.