← 返回首页
GitHub - peter-evans/sendgrid-action: A GitHub Action to send email with SendGrid · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

peter-evans/sendgrid-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 master
Go to file
Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
View all files

Repository files navigation

More items

SendGrid Action

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: 'recipient@example.org', from: 'sender@example.org', 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: 'recipient@example.org', from: 'sender@example.org', 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

About

A GitHub Action to send email with SendGrid

Topics

Resources

License

Stars

35 stars

Watchers

2 watching

Forks

Packages

 
 
 

Contributors

Footer

© 2026 GitHub, Inc.