How to Connect to SendinBlue and Use a Template with JSON?

This topic was automatically generated from Slack. You can find the original thread here.

i want to send emails via sendinblue. I need the json to connect to sendinblue and use a template

To send emails using SendinBlue and a template, you can use the SendinBlue “Send Transactional Email” action in Pipedream. Here’s an example of how to use this action in a Pipedream component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { apiKey: { type: "string", label: "SendinBlue API Key", secret: true, }, templateId: { type: "integer", label: "Template ID", }, to: { type: "string", label: "Recipient Email", }, }, async run({ $ }) { const response = await axios($, { method: "POST", url: "https://api.sendinblue.com/v3/smtp/email", headers: { "api-key": this.apiKey, "Content-Type": "application/json", }, data: { templateId: this.templateId, to: [{ email: [this.to](http://this.to) }], }, }); return response; }, }); Replace the apiKey prop value with your SendinBlue API key, the templateId prop value with the ID of the template you want to use, and the to prop value with the recipient’s email address. This component will send an email using the specified template to the recipient.

ok how das it work with more than one email address? Addresses come from a json array

To send emails to multiple recipients using a JSON array of email addresses, you can use the Pipedream component with the SendGrid API. First, make sure you have the SendGrid API key and import the axios package from @pipedream/platform. Here’s an example component that sends an email to multiple recipients: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { apiKey: { type: "string", label: "SendGrid API Key", secret: true, }, fromEmail: { type: "string", label: "From Email", }, emailAddresses: { type: "string[]", label: "Email Addresses", }, subject: { type: "string", label: "Subject", }, content: { type: "string", label: "Content", }, }, async run() { const recipients = this.emailAddresses.map((email) => ({ email })); const data = { personalizations: [ { to: recipients, }, ], from: { email: this.fromEmail, }, subject: this.subject, content: [ { type: "text/plain", value: this.content, }, ], }; const config = { method: "POST", url: "https://api.sendgrid.com/v3/mail/send", headers: { Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json", }, data, }; const response = await axios(this, config); return response; }, }); In this example, the emailAddresses prop accepts a JSON array of email addresses. The component maps the email addresses to the required format for the SendGrid API and sends the email to all recipients. Make sure to replace the placeholders with your actual SendGrid API key and other required information.

i want to send emails via sendinblue. I need the json to connect to sendinblue and use a template. I want to send mails to a lot of emailaddresses. addresses come from a json array {{steps.get_request.$return_value[0].cstEmail}}

To send emails using SendinBlue and a template, you can use the SendinBlue Send Transactional Email action in Pipedream. Here’s an example of how to set up the component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { apiKey: { type: "string", label: "SendinBlue API Key", }, templateId: { type: "integer", label: "Template ID", }, toAddresses: { type: "string[]", label: "Recipient Email Addresses", }, }, async run({ steps }) { const url = "https://api.sendinblue.com/v3/smtp/email"; const headers = { "api-key": this.apiKey, "Content-Type": "application/json", }; const data = { templateId: this.templateId, to: this.toAddresses.map((email) => ({ email })), }; const response = await axios(this, { method: "POST", url, headers, data, }); return response; }, }); Replace the apiKey and templateId with your SendinBlue API key and the template ID you want to use. For the toAddresses prop, you can use the JSON array from the previous step like this: { "toAddresses": "{{steps.get_request.$return_value[0].cstEmail}}" } This component will send emails using the specified template to the email addresses provided in the toAddresses array.

got this as error massage
this.toAddresses.map is not a function

I send via sendinblue api and json emails to different recipients. I can see all recipients in the email program. but this should not be so. I only want everyone to see their address, not the others. How can I prevent this

To send emails to multiple recipients without them seeing each other’s addresses, you can use the Twilio SendGrid “Send Email Multiple Recipients” action in Pipedream. This action sends a personalized email to multiple specified recipients without revealing their addresses to each other. Here’s the component key for this action: ```
sendgrid-send-email-multiple-recipients

Appreciate you using Mario and apologies for the half-right answers. This specific issue where it gives answers for the wrong app is on our radar and I’m working on a fix!

Hi ,
the answers were not so bad. The problem could almost be solved. I just have to figure out how to make it so that not all recipients get to see the recipient list.

How do I send Sendinblue emails with an array of recipients BCCd? I want a response for Sendinblue, not Sendgrid

To send a Sendinblue email with an array of recipients BCC’d, you can use the Sendinblue “Send Transactional Email” action in Pipedream. First, make sure you have the Sendinblue integration set up in your Pipedream account. Here’s an example of how to use the Sendinblue “Send Transactional Email” action with BCC recipients: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { apiKey: { type: "string", label: "Sendinblue API Key", secret: true, }, fromEmail: { type: "string", label: "From Email", }, fromName: { type: "string", label: "From Name", }, toEmail: { type: "string", label: "To Email", }, subject: { type: "string", label: "Subject", }, content: { type: "string", label: "Content", }, bccEmails: { type: "string[]", label: "BCC Emails", }, }, async run({ $ }) { const bcc = this.bccEmails.map((email) => ({ email })); const payload = { sender: { email: this.fromEmail, name: this.fromName, }, to: [ { email: this.toEmail, }, ], bcc, subject: this.subject, htmlContent: this.content, }; const response = await axios($, { method: "POST", url: "https://api.sendinblue.com/v3/smtp/email", headers: { "api-key": this.apiKey, "Content-Type": "application/json", }, data: payload, }); return response; }, }); Replace the apiKey, fromEmail, fromName, toEmail, subject, content, and bccEmails props with your own values. The bccEmails prop should be an array of email addresses you want to BCC. This component will send an email using Sendinblue’s API with the specified BCC recipients.

Write me a json to update a contact via sendinblue api

To update a contact using Sendinblue API, you can make a PUT request to the /contacts/{email} endpoint. Here’s an example of how to update a contact using a Pipedream component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { apiKey: { type: "string", label: "Sendinblue API Key", secret: true, }, email: { type: "string", label: "Contact Email", }, updateData: { type: "object", label: "Update Data", }, }, async run({ $ }) { const url = `https://api.sendinblue.com/v3/contacts/${encodeURIComponent(this.email)}`; const headers = { "api-key": this.apiKey, "Content-Type": "application/json", }; const response = await axios($, { method: "PUT", url, headers, data: this.updateData, }); return response; }, }); Replace the apiKey, email, and updateData props with your own values. The updateData prop should be a JSON object containing the fields you want to update for the contact. This component will update the contact with the specified email address using Sendinblue’s API.