How to use @sendgrid/helpers - 8 common examples

To help you get started, we’ve selected a few @sendgrid/helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github looker / actions / src / integrations / looker / test_looker_dashboard_api.ts View on Github external
request.scheduledPlan = {
        title: "Hello attachment",
        url: "https://mycompany.looker.com/look/1",
      }
      request.formParams = {
        to: "test@example.com",
      }
      request.attachment = {dataJSON: {
        fields: [{name: "coolfield", tags: ["looker_dashboard_url"]}],
        data: [
          {coolfield: {value: "/dashboards/1?myfield=Yes"}},
        ],
      }}
      const url = "https://mycompany.looker.com/dashboards/1?myfield=Yes"
      /* tslint:disable max-line-length */
      const msg = new helpers.classes.Mail({
        to: request.formParams.to!,
        subject: request.scheduledPlan.title!,
        from: "Looker ",
        text: `View this data in Looker. ${url}\nResults are attached.`,
        html: `<p>View this data in Looker.</p><p><a href="${url}">${request.scheduledPlan.title!} 0</a></p><p>Results are attached.</p>`,
      })
      msg.addAttachment({
        content: "pdf content",
        filename: sanitizeFilename("Hello attachment_0.pdf"),
        type: "application/pdf",
      })
      return expectLookerAPIActionMatch(request, "/dashboards/1?myfield=Yes", msg)
    })
github looker / actions / src / actions / sendgrid / test_sendgrid.ts View on Github external
it("sends right body to filename and address", () =&gt; {
      const request = new Hub.ActionRequest()
      request.scheduledPlan = {
        title: "Hello attachment",
        url: "https://mycompany.looker.com/look/1",
      }
      request.formParams = {
        to: "test@example.com",
      }
      request.attachment = {dataBuffer: Buffer.from("1,2,3,4", "utf8")}

      const msg = new helpers.classes.Mail({
        to: request.formParams.to,
        subject: request.scheduledPlan.title as string,
        from: "Looker ",
        text: `View this data in Looker. ${request.scheduledPlan.url}\n Results are attached.`,
        html: `<p><a href="${request.scheduledPlan.url}">View this data in Looker.</a></p><p>Results are attached.</p>`,
        attachments: [{
          content: request.attachment.dataBuffer!.toString(request.attachment.encoding),
          filename: stubFilename,
        }],
      })

      return expectSendGridMatch(request, msg)
    })
github looker / actions / src / integrations / looker / test_looker_dashboard_api.ts View on Github external
it("sends right params for cell", async () =&gt; {
      const request = new D.ActionRequest()
      request.type = "cell"
      request.params = {
        base_url: "https://mycompany.looker.com:19999/api/3.0",
        value: "/dashboards/1?myfield=Yes",
      }
      request.scheduledPlan = {
        title: "Hello attachment",
        url: "https://mycompany.looker.com/look/1",
      }
      request.formParams = {
        to: "test@example.com",
      }
      const url = "https://mycompany.looker.com/dashboards/1?myfield=Yes"
      const msg = new helpers.classes.Mail({
        to: request.formParams.to!,
        subject: request.scheduledPlan.title!,
        from: "Looker ",
        text: `View this data in Looker. ${url}\nResults are attached.`,
        html: `<p>View this data in Looker.</p><p><a href="${url}">${request.scheduledPlan.title!} 0</a></p><p>Results are attached.</p>`,
      })
      msg.addAttachment({
        content: "pdf content",
        filename: sanitizeFilename("Hello attachment_0.pdf"),
        type: "application/pdf",
      })
      return expectLookerAPIActionMatch(request, "/dashboards/1?myfield=Yes", msg)
    })
github looker / actions / src / actions / sendgrid / test_sendgrid.ts View on Github external
it("sends with right subject if specified", () =&gt; {
      const request = new Hub.ActionRequest()
      request.scheduledPlan = {
        title: "Hello attachment",
        url: "https://mycompany.looker.com/look/1",
      }
      request.formParams = {
        to: "test@example.com",
        filename: "mywackyfilename",
        subject: "mysubject",
      }
      request.attachment = { dataBuffer: Buffer.from("1,2,3,4", "utf8") }

      const msg = new helpers.classes.Mail({
        to: request.formParams.to,
        subject: request.formParams.subject,
        from: "Looker ",
        text: `View this data in Looker. ${request.scheduledPlan.url}\n Results are attached.`,
        html: `<p><a href="${request.scheduledPlan.url}">View this data in Looker.</a></p><p>Results are attached.</p>`,
        attachments: [{
          content: request.attachment.dataBuffer!.toString(request.attachment.encoding),
          filename: request.formParams.filename!,
        }],
      })

      return expectSendGridMatch(request, msg)
    })
github sendgrid / sendgrid-nodejs / test / typescript / helpers.ts View on Github external
import * as helpers from "@sendgrid/helpers";
new helpers.classes.Attachment({
    content: "",
    filename: "test.txt",
    type: "text/plain"
});

new helpers.classes.EmailAddress("someone@example.org");
new helpers.classes.EmailAddress({ name: "Some One", email: "someone@example.org" });

new helpers.classes.Personalization({
    to: "someone@example.org",
    subject: "Hello Some One",
    dynamicTemplateData: {
        translations: {
            hello: "Привет!"
        },
        count: 1
github sendgrid / sendgrid-nodejs / test / typescript / helpers.ts View on Github external
import * as helpers from "@sendgrid/helpers";
new helpers.classes.Attachment({
    content: "",
    filename: "test.txt",
    type: "text/plain"
});

new helpers.classes.EmailAddress("someone@example.org");
new helpers.classes.EmailAddress({ name: "Some One", email: "someone@example.org" });

new helpers.classes.Personalization({
    to: "someone@example.org",
    subject: "Hello Some One",
    dynamicTemplateData: {
        translations: {
            hello: "Привет!"
        },
        count: 1
    }
});

new helpers.classes.Mail({
    to: "someone@example.org",
    from: "someone@example.org",
github looker / actions / src / actions / sendgrid / sendgrid.ts View on Github external
async execute(request: Hub.ActionRequest) {
    if (!request.attachment || !request.attachment.dataBuffer) {
      throw "Couldn't get data from attachment."
    }

    if (!request.formParams.to) {
      throw "Needs a valid email address."
    }
    const filename = request.formParams.filename || request.suggestedFilename() as string
    const plan = request.scheduledPlan
    const subject = request.formParams.subject || (plan &amp;&amp; plan.title ? plan.title : "Looker")
    const from = request.formParams.from ? request.formParams.from : "Looker "

    const msg = new helpers.classes.Mail({
      to: request.formParams.to,
      subject,
      from,
      text: plan &amp;&amp; plan.url ?
          `View this data in Looker. ${plan.url}\n Results are attached.`
        :
          "Results are attached.",
      html: plan &amp;&amp; plan.url ?
          `<p><a href="${plan.url}">View this data in Looker.</a></p><p>Results are attached.</p>`
        :
          "Results are attached.",
      attachments: [{
        content: request.attachment.dataBuffer.toString(request.attachment.encoding),
        filename,
      }],
    })
github looker / actions / src / integrations / looker / looker_dashboard_api.ts View on Github external
const parsedLookerUrl = URL.parse(lookerUrl)
      if (!parsedLookerUrl.pathname) {
        throw `Malformed ${TAG} URL`
      }
      parsedUrl.port = ""
      parsedUrl.pathname = parsedLookerUrl.pathname
      parsedUrl.search = parsedLookerUrl.search || ""
      return parsedUrl.href
    })

    const displayUrlsText = displayUrls.map((lookerUrl) =&gt; (`${lookerUrl}\n`)).join("")
    const displayUrlsHTML = displayUrls.map((lookerUrl, i) =&gt; (
      `<p><a href="${lookerUrl}">${subject} ${i}</a></p>`
    )).join("")

    const msg = new helpers.classes.Mail({
      to: req.formParams.to!,
      subject,
      from,
      text: `View this data in Looker. ${displayUrlsText}Results are attached.`,
      html: `<p>View this data in Looker.</p>${displayUrlsHTML}<p>Results are attached.</p>`,
    })

    await Promise.all(lookerUrls.map(async (lookerUrl, i) =&gt; {
      const pdf = await this.generatePDFDashboard(client, lookerUrl, req.formParams.format)
      msg.addAttachment({
        content: pdf.toString("base64"),
        filename: sanitizeFilename(`${subject}_${i}.pdf`),
        type: "application/pdf",
      })
    }))
    let response

@sendgrid/helpers

Twilio SendGrid NodeJS internal helpers

MIT
Latest version published 12 months ago

Package Health Score

91 / 100
Full package analysis

Popular @sendgrid/helpers functions

Similar packages