Skip to content

Commit

Permalink
Add support for copying in CC distribution lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Apr 30, 2020
1 parent cfc309b commit 4907537
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
SENDGRID_API_TOKEN: ${{ secrets.SENDGRID_API_TOKEN }}
RECIPIENTS_URL: ${{ secrets.RECIPIENTS_URL }}
SENDER_EMAIL: ${{ secrets.SENDER_EMAIL }}
DISTRIBUTION_LISTS: ${{ secrets.DISTRIBUTION_LISTS }}
```
### 2. Set the SendGrid secret
Expand All @@ -48,10 +49,14 @@ [email protected]

If you don't know where to host this file, just go to [GitHub Gists](https://gist.github.com) and create a new textfile with the e-mails you want to target. After you save the file just click `raw` and get the URI of the file you've just created.

### 3. Set the SENDER_EMAIL secret
### 4. Set the DISTRIBUTION_LISTS secret (Optional)

Do the same for a secret named `DISTRIBUTION_LISTS`. The secret contents is a comma separated list of e-mails for other lists (This e-mails will be put in CC in the outgoing mail).

### 5. Set the SENDER_EMAIL secret

Do the same for a secret named `SENDER_EMAIL` including the e-mail to be used in the `from:` field on the mail message.

### 4. Test the workflow!
### 6. Test the workflow!

Create a new release for your repository and verify that the action triggers and that the e-mails were sent. Sometimes it's worth checking the spam inbox.
1 change: 1 addition & 0 deletions env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SENDGRID_API_TOKEN=
RECIPIENTS_URL=
DISTRIBUTION_LISTS=
SENDER_EMAIL=
GITHUB_EVENT_PATH=
10 changes: 6 additions & 4 deletions src/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sendgridMail = require('@sendgrid/mail');

const setCredentials = () => sendgridMail.setApiKey(process.env.SENDGRID_API_TOKEN);

async function prepareMessage(recipients) {
async function prepareMessage(recipients, lists) {
const { repository, release } = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));

const converter = new showdown.Converter();
Expand Down Expand Up @@ -33,15 +33,17 @@ async function prepareMessage(recipients) {
email: sender,
},
to: sender,
cc: lists,
bcc: recipients,
subject,
html: releaseBody,
};
}
async function run(recipientsUrl) {
async function run(recipientsUrl, distributionLists) {
const { data } = await axios.get(recipientsUrl);
const recipients = data.split(/\r\n|\n|\r/);
const message = await prepareMessage(recipients);
const lists = distributionLists ? distributionLists.split(',') : [];
const message = await prepareMessage(recipients, lists);
await sendgridMail.send(message);
console.log('Mail sent!');
}
Expand All @@ -50,7 +52,7 @@ async function run(recipientsUrl) {
* Run
*/
setCredentials();
run(process.env.RECIPIENTS_URL)
run(process.env.RECIPIENTS_URL, process.env.DISTRIBUTION_LISTS)
.catch((error) => {
console.error(error);
process.exit(1);
Expand Down

0 comments on commit 4907537

Please sign in to comment.