Closed teddis closed 7 years ago
Hello @teddis,
At first glance, I don't see any obvious error. I've tested the code in sendEmail
and it appears to work as designed. I will add this to our backlog for further investigation.
Meanwhile, I have a few questions:
console.error(err)
)? Is anything logged on your end (via console.log(response)
)?mail.toJSON()
to make sure the payload is correct.With Best Regards,
Elmer
Thanks, Elmer. The sg.API
promise doesn't seem to return at all which is odd, so nothing is logged for success or failure. The JSON output logged for mail.toJSON
is the following but looks fine to me:
{ from: { email: 'support@orderscape.com', name: 'Support' },
personalizations:
[ Personalization {
tos: [ { email: 'ted@orderscape.com', name: undefined } ],
ccs: undefined,
bccs: undefined,
subject: undefined,
headers: undefined,
substitutions: undefined,
custom_args: undefined,
send_at: undefined,
addTo: [Function],
getTos: [Function],
addCc: [Function],
getCcs: [Function],
addBcc: [Function],
getBccs: [Function],
setSubject: [Function],
getSubject: [Function],
addHeader: [Function],
getHeaders: [Function],
addSubstitution: [Function],
getSubstitutions: [Function],
addCustomArg: [Function],
getCustomArgs: [Function],
setSendAt: [Function],
getSendAt: [Function],
toJSON: [Function] } ],
subject: 'Simple HTML test Wed Mar 15 2017 13:47:25 GMT-0400 (AST)',
content:
[ { type: 'text/html',
value: '<html><body><h1>some text here</h1></body></html>' } ],
attachments: undefined,
template_id: undefined,
sections: undefined,
headers: undefined,
categories: undefined,
custom_args: undefined,
send_at: undefined,
batch_id: undefined,
asm: undefined,
ip_pool_name: undefined,
mail_settings: undefined,
tracking_settings: undefined,
reply_to: undefined }
Btw I also tried using the callback version which also did not call back:
return new Promise((resolve, reject) => {
sg.API(request, (response) => {
console.log("*** response:", response);
resolve();
});
});
Something must be wrong with the request?
Thanks for digging deeper @teddis,
Can you compare the mail.toJSON
output with the successful plain/text call?
Only subject and contents are slightly different. Again, there is no output from the successful plain/test call, but the side effect is that I receive the email, unlike HTML.
Can you try hard coding the html in your email.txt
file.
Also, can you try without using the Mail Helper? https://github.com/sendgrid/sendgrid-nodejs#without-mail-helper-class
@thinkingserious, ok getting somewhere. I tried hard coding without mail helper and no difference btw. The trick to get error below was not using mocha which was hiding it for some reason. Why is my auth grant a problem? I created a new API key the other day. I've gone through several to try and fix this before.
sendgrid request: { host: '',
method: 'POST',
path: '/v3/mail/send',
headers: {},
body:
{ personalizations:
[ { to: [ { email: 'ted@orderscape.com' } ],
subject: 'Simple HTML test Wed Mar 15 2017 15:41:10 GMT-0400 (AST)' } ],
from: { email: 'support@orderscape.com', name: 'Support' },
content:
[ { type: 'text/html',
value: '<html><body><h1>some text here</h1></body></html>' } ] },
queryParams: {},
test: false,
port: '' }
*** error { SendGridError: Response error
at /Users/ted/src/orderscape/foodiebot/node_modules/sendgrid/lib/sendgrid.js:100:23
at IncomingMessage.<anonymous> (/Users/ted/src/orderscape/foodiebot/node_modules/sendgrid-rest/lib/client.js:108:9)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
message: 'Response error',
response:
{ statusCode: 401,
body:
{ errors:
[ { message: 'The provided authorization grant is invalid, expired, or revoked',
field: null,
help: null } ] },
headers:
{ server: 'nginx',
date: 'Wed, 15 Mar 2017 19:41:10 GMT',
'content-type': 'application/json',
'content-length': '116',
connection: 'close',
'x-frame-options': 'DENY',
'access-control-allow-origin': 'https://sendgrid.api-docs.io',
'access-control-allow-methods': 'POST',
'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
'access-control-max-age': '600',
'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html' } } }
Hi @teddis,
With regards to your API Key, this is an issue our support team can help with. They can be reached at https://support.sendgrid.com
Thanks for sharing that mocha tidbit, I'm sure that will help someone with a similar issue in the future.
With Best Regards,
Elmer
Issue Summary
I'm using Sendgrid's NodeJS package to send text and/or HTML email. The package (1) never returns from sg.API promise when sending
text/html
, (2) doesn't update the Dashboard's activity as being sent, and (3) doesn't send the message. However, sendingtext/plain
works fine. Using Curl sends HTML fine as well.Steps to Reproduce
See attached files. test_email.txt email.txt
test_email.txt
email.txt
Technical details: