Github action to send an mail using the Mailgun API. This is a re-usable Github Action that you can use to send mail for any purposes every time some event trigger for a repository.
Required Mailgun API Key.
Required Your Domain Name.
Required Email address of the recipient(s). Example: bob@host.com. You can use commas to separate multiple recipients.
The email that will be shown as sender. Default will be hello@+your domain name. Like - hello@example.com
Email subject. Default is "${GITHUB_ACTOR} (${GITHUB_EVENT_NAME}) at ${GITHUB_REPOSITORY}".
Body of the email (HTML Supported). Default is "${GITHUB_ACTOR} (${GITHUB_EVENT_NAME}) at ${GITHUB_REPOSITORY}".
Email response from Mailgun.
For subject and body we can use environment variables and event payload in following way -
Environment variables can be interpolated in the message using brackets ({{
and }}
). Like -
Action Called : {{ GITHUB_ACTION }}
Event Payload data can also be interpolated in the message using brackets ({{
and }}
) with the EVENT_PAYLOAD
variable. Like -
Action Called: {{ GITHUB_ACTION }} as {{ EVENT_PAYLOAD.pull_request.id }}
Check example section for more usages. Also see all event types for valid payload informations.
name: On Push Email
on: [push]
jobs:
send-mail:
runs-on: ubuntu-latest
name: Send email on every push
steps:
- name: Send Mail Action
id: sendmail
uses: vineetchoudhary/mailgun-action@v1.0
with:
api-key: ${{ secrets.API_KEY }}
domain: ${{ secrets.DOMAIN }}
to: ${{ secrets.TO }}
- name: Send Mail Action Response
run: echo "${{ steps.sendmail.outputs.response }}"
Trigger an email when someone comment on a issue with custom subject and body.
name: Issue Activity
on:
issue_comment:
types: [created, edited, deleted]
jobs:
send-mail:
runs-on: ubuntu-latest
name: Send email when issue created/edited/deleted
steps:
- name: Send Mail Action
id: sendmail
uses: vineetchoudhary/mailgun-action@v1.0
with:
api-key: ${{ secrets.API_KEY }}
domain: ${{ secrets.DOMAIN }}
to: ${{ secrets.TO }}
subject: 'Issue Activity - {{ EVENT_PAYLOAD.action }}'
body: '<p><b>Body</b> - {{ EVENT_PAYLOAD.comment.body }} <br /><br /><b>Issue Activity</b> - {{ EVENT_PAYLOAD.action }}. <br /><br /><b>URL</b> - {{ EVENT_PAYLOAD.comment.html_url }} <br /><br /><b>By</b> - {{ EVENT_PAYLOAD.comment.user.login }}</p>'
- name: Send Mail Action Response
run: echo "${{ steps.sendmail.outputs.response }}"