New error when trying to send email via SendGrid A...
# 🤝help
r
Used this code to successfully setup a custom node to send an email: https://botpress.com/docs/cloud/getting-started/tips-and-tricks/#send-emails-using-sendgrid-api Now it is resulting in the following error: [TypeError, Cannot read properties of undefined (reading 'length')]. My API credentials are working as expected and nothing has changed to cause this error.
f
Could you share your code without the API key?
r
It is the exact same from the tutorial. Even reloading the code from the link above and changing my API key results in the same error.
f
I also got that
f
this following code should work well. I don't get any errors my end.
const sendEmail = async (to, subject, body) => { const apiKey = 'YOUR API KEY' const url = 'https://api.sendgrid.com/v3/mail/send' const payload = { personalizations: [ { to: [{ email: to }], subject: subject } ], from: { email: 'YOUR SEND FROM EMAIL' }, content: [{ type: 'text/plain', value: body }] } const headers = { Authorization:
Bearer ${apiKey}
, 'Content-Type': 'application/json' } await axios.post(url, payload, { headers }) } const to = 'SEND TO EMAIL HERE' const subject = 'EMAIL SUBJECT HERE' const body =
EMAIL BODY HERE. YOU CAN ADD VARIABLES
await sendEmail(to, subject, body)
email body must be inbetween backticks > these ``
if you want to add variables in the body they must be formated like this: ${workflow.variablename}
c
Thanks @freezing-carpenter-9818 !
r
@freezing-carpenter-9818 tried the code above, still receiving same error.
my apologies @freezing-carpenter-9818 , the code should work. I realized the error was on my end and due to new requirements for sendgrid api. the sending email did not match my verified senders (typo) Here is the entire error showing when trying curl : The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements" thanks again!
f
yes you must verify a sender and use that email address for the send from email
let me know if you get it working
r
yes, it is working. it was a typo on my end for the from email
c
Good to know it's working now! Marking this thread as solved.
10 Views