Git Product home page Git Product logo

sendgrid-action's Introduction

SendGrid Action

GitHub Marketplace

A GitHub Action to send email with SendGrid.

The action executes a Node.js script allowing you to customise sending email with the Node.js API Library.

Usage

    - name: SendGrid
      uses: peter-evans/sendgrid-action@v1
      env:
        SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}

Secrets

Set your SendGrid API key as a secret with the name SENDGRID_API_KEY. If you don't have one you can sign up and get 100 emails per day for free here.

Optionally specifying the script file path

The action assumes there is a Node.js script located at .github/sendgrid.js. This path can be overridden with an environment variable.

    - name: SendGrid
      uses: peter-evans/sendgrid-action@v1
      env:
        SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
        SCRIPT_FILEPATH: ./some-path/email-sending-script.js

Example script files

The following examples are quite basic use cases. For more complicated use cases see the list of examples here.

Sending a single email to a single recipient:

#! /usr/bin/env node

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const msg = {
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Hello world',
    text: 'Hello plain world!',
    html: '<p>Hello HTML world!</p>',
};

sgMail
    .send(msg)
    .then(() => console.log('Mail sent successfully'))
    .catch(error => console.error(error.toString()));

Sending an attachment:

#! /usr/bin/env node

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const fs = require('fs'),
    filename = 'hello-world.pdf',
    fileType = 'application/pdf',
    data = fs.readFileSync('attachments/' + filename);

const msg = {
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Hello world',
    text: 'Hello plain world!',
    html: '<p>Hello HTML world!</p>',
    attachments: [
        {
            content: data.toString('base64'),
            filename: filename,
            type: fileType,
            disposition: 'attachment',
        },
    ],
};

sgMail
    .send(msg)
    .then(() => console.log('Mail sent successfully'))
    .catch(error => console.error(error.toString()));

Note: Your script file must be executable otherwise it will cause a permission denied error. Make it executable with this command.

chmod +x email-sending-script.js

License

MIT

sendgrid-action's People

Contributors

ianrios avatar peter-evans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sendgrid-action's Issues

why didn't the recipient receive the mail?

I followed the usage.
And the Github Action worked without error.
image

But the recipient didn't receive the mail, just nothing happened...

This is my sendgrid.js

const sgMail = require('@sendgrid/mail');
console.log(sgMail)
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const msg = {
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Hello world',
    text: 'Hello plain world!',
    html: '<p>Hello HTML world!</p>',
};

sgMail
    .send(msg)
    .then(() => console.log('Mail sent successfully'))
    .catch(error => console.error(error.toString()));

BTW, i didn't find it in the junk mail, and the recipient email address is valid and real.
Please help me..
This is my repo

How can i pass dynamic value as part of the email body

This Works well as long as body of the email is static. But what if i want to add something dynamically in the mail body ?

Basically this is what i want to do through github actions

1> Execute test cases through CI/CD pipelines
2> Upload coverage report to bucket on cloud (Initally wanted to send that as an attachment but gmail blocks attachment with .js extension)
3> Send email with the link of the uploaded report through sendgrid actions

I am able to achieve all 3 except i am not able to dynamically change the body of the email based on the output of other actions

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.