17 Commits
v2 ... v3.2.0

Author SHA1 Message Date
db36373cbe 🤘 Implementation for #59 to support username and password as optional (#60)
Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
2021-06-14 20:04:27 +02:00
98b61f505d Make custom secure ports available (#51) 2021-05-03 18:02:47 +02:00
938c7ffae5 Merge pull request #50 from dawidd6/dependabot-add-v2-config-file
Upgrade to GitHub-native Dependabot
2021-04-29 23:45:28 +02:00
d892e3932a Upgrade to GitHub-native Dependabot 2021-04-29 15:35:41 +00:00
c88d504a7c README: update
[skip ci]
2021-04-25 16:45:57 +02:00
16ca24fcf8 README: missing dot
[skip ci]
2021-04-25 16:43:10 +02:00
b5690f2fd6 README: hide link
[skip ci]
2021-04-25 16:42:37 +02:00
21a68c2b95 workflows: fix 2021-04-25 16:36:40 +02:00
a305c08e85 README: name 2021-04-25 16:30:16 +02:00
f94f0e37fa workflows: fix input
[skip ci]
2021-04-25 16:23:58 +02:00
75773ecb8c workflows: adjust tests 2021-04-25 16:20:37 +02:00
63f6c7e5d2 main: don't convert markdown in plain body ever 2021-04-25 16:19:34 +02:00
b738850ab1 main: style fix 2021-04-25 16:14:13 +02:00
c938b3cb85 support multipart email (#48)
Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
2021-04-25 16:11:54 +02:00
32390e9a18 Merge pull request #46 from dawidd6/dependabot-npm_and_yarn-actions-core-1.2.7
build(deps): bump @actions/core from 1.2.6 to 1.2.7
2021-04-14 09:14:45 +02:00
b7c5d1ceb6 build(deps): bump @actions/core from 1.2.6 to 1.2.7
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.6 to 1.2.7.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-14 04:58:57 +00:00
df34b4ded5 Updates README.md to reflect changes suggested in issue #43 relating to changing gmail settings (#45)
Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
2021-04-13 20:24:22 +02:00
7 changed files with 125 additions and 74 deletions

24
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,24 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "04:00"
pull-request-branch-name:
separator: "-"
open-pull-requests-limit: 10
ignore:
- dependency-name: nodemailer
versions:
- 6.4.18
- 6.5.0
- 6.6.0
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "04:00"
pull-request-branch-name:
separator: "-"
open-pull-requests-limit: 10

View File

@ -13,12 +13,14 @@ jobs:
max-parallel: 1 max-parallel: 1
matrix: matrix:
include: include:
- content_type: text/markdown - subject: Plain body (attachment)
attachments: action.yml attachments: action.yml
body: file://README.md
- content_type: text/html
attachments: package.json,package-lock.json
body: | body: |
first line
second line
- subject: HTML body (attachments)
attachments: package.json,package-lock.json
html_body: |
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
@ -26,16 +28,16 @@ jobs:
<p>Paragraph</p> <p>Paragraph</p>
</body> </body>
</html> </html>
- content_type: text/html - subject: Plain body (Markdown)
convert_markdown: true convert_markdown: true
body: | body: file://README.md
# h1 - subject: HTML body (Markdown)
## h2 convert_markdown: true
### h3 html_body: file://README.md
**bold** - subject: Multipart body (Markdown)
_italics_ convert_markdown: true
- bullet 1 body: file://README.md
- bullet 2 html_body: file://README.md
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -46,10 +48,10 @@ jobs:
server_port: 465 server_port: 465
username: ${{secrets.USERNAME}} username: ${{secrets.USERNAME}}
password: ${{secrets.PASSWORD}} password: ${{secrets.PASSWORD}}
subject: ${{github.repository}} subject: ${{matrix.subject}}
body: ${{matrix.body}} body: ${{matrix.body}}
html_body: ${{matrix.html_body}}
to: ${{github.event.pusher.email}} to: ${{github.event.pusher.email}}
from: github-actions from: github-actions
content_type: ${{matrix.content_type}}
convert_markdown: ${{matrix.convert_markdown}}
attachments: ${{matrix.attachments}} attachments: ${{matrix.attachments}}
convert_markdown: ${{matrix.convert_markdown}}

View File

@ -2,35 +2,68 @@
An action that simply sends a mail to multiple recipients. An action that simply sends a mail to multiple recipients.
Some features:
- plain text body
- HTML body
- multipart body (plain text + HTML)
- Markdown to HTML converting
- file attachments
## Usage ## Usage
```yaml ```yaml
- name: Send mail - name: Send mail
uses: dawidd6/action-send-mail@v2 uses: dawidd6/action-send-mail@v3
with: with:
# Required mail server address:
server_address: smtp.gmail.com server_address: smtp.gmail.com
# Required mail server port:
server_port: 465 server_port: 465
# Optional (recommended): mail server username:
username: ${{secrets.MAIL_USERNAME}} username: ${{secrets.MAIL_USERNAME}}
# Optional (recommended) mail server password:
password: ${{secrets.MAIL_PASSWORD}} password: ${{secrets.MAIL_PASSWORD}}
# Required mail subject:
subject: Github Actions job result subject: Github Actions job result
# Literal body: # Required recipients' addresses:
body: Build job of ${{github.repository}} completed successfully!
# Read file contents as body:
body: file://README.md
to: obiwan@example.com,yoda@example.com to: obiwan@example.com,yoda@example.com
# Required sender full name (address can be skipped):
from: Luke Skywalker # <user@example.com> from: Luke Skywalker # <user@example.com>
# Optional carbon copy recipients # Optional whether this connection use TLS (default is true if server_port is 465)
secure: true
# Optional plain body:
body: Build job of ${{github.repository}} completed successfully!
# Optional HTML body read from file:
html_body: file://README.html
# Optional carbon copy recipients:
cc: kyloren@example.com,leia@example.com cc: kyloren@example.com,leia@example.com
# Optional blind carbon copy recipients # Optional blind carbon copy recipients:
bcc: r2d2@example.com,hansolo@example.com bcc: r2d2@example.com,hansolo@example.com
# Optional recipient of the email response # Optional recipient of the email response:
reply_to: luke@example.com reply_to: luke@example.com
# Optional unsigned/invalid certificates allowance: # Optional unsigned/invalid certificates allowance:
ignore_cert: true ignore_cert: true
# Optional content type (defaults to text/plain):
content_type: text/html
# Optional converting Markdown to HTML (set content_type to text/html too): # Optional converting Markdown to HTML (set content_type to text/html too):
convert_markdown: true convert_markdown: true
# Optional attachments: # Optional attachments:
attachments: attachments.zip,git.diff,./dist/static/main.js attachments: attachments.zip,git.diff,./dist/static/main.js
``` ```
## Troubleshooting
### Gmail
Gmail security settings may cause this Action to fail. This failure may involve a message in the GitHub Actions details about access being denied and an email from Google to the email account being used about a sign-in being blocked and why.
Changes in Gmail settings may be necessary to get this action to work.
1. Google treats this method of using email as a "Less Secure App". However, "Less Secure Apps" can be enabled in Google profile settings. There doesn't appear to be a static link for this, but if you go to Google profile settings while signed-in and type "less secure apps" into the search bar, the appropriate instructions will come up.
2. IMAP needs to be enabled in Gmail settings as described [here](https://support.google.com/mail/answer/7126229?hl=en).
3. If the Gmail account you're trying to use in this Action is already 2FA (Two Factor Authentication) enabled, the 2FA password will need to be provided as well, which isn't included in the default template.
Users who have had problems have reported success by doing each of these three steps or by doing the first two steps and using a Gmail account that didn't have 2FA enabled.
### Unauthenticated login (username/password fields)
The parameters `username` and `password` are set as optional to support self-hosted runners access to on-premise infrastructure. If
you are accessing public email servers make sure you provide a username/password authentication through [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to make the email delivery secure.

View File

@ -13,22 +13,28 @@ inputs:
required: true required: true
username: username:
description: Authenticate as this user to SMTP server description: Authenticate as this user to SMTP server
required: true required: false
password: password:
description: Authenticate with this password to SMTP server description: Authenticate with this password to SMTP server
required: true required: false
subject: subject:
description: Subject of mail message description: Subject of mail message
required: true required: true
body:
description: Body of mail message (might be a filename prefixed with file:// to read from)
required: true
to: to:
description: Recipients mail addresses (separated with comma) description: Recipients mail addresses (separated with comma)
required: true required: true
from: from:
description: Full name of mail sender (might be with an email address specified in <>) description: Full name of mail sender (might be with an email address specified in <>)
required: true required: true
secure:
description: Whether this connection use TLS (default is true if server_port is 465)
required: false
body:
description: Body of mail message (might be a filename prefixed with file:// to read from)
required: false
html_body:
description: HTML body of mail message (might be a filename prefixed with file:// to read from)
required: false
cc: cc:
description: Carbon copy recipients (separated with comma) description: Carbon copy recipients (separated with comma)
required: false required: false
@ -41,10 +47,6 @@ inputs:
ignore_cert: ignore_cert:
description: Allow unsigned/invalid certificates description: Allow unsigned/invalid certificates
required: false required: false
content_type:
description: Content-Type HTTP header (text/html or text/plain)
required: false
default: text/plain
convert_markdown: convert_markdown:
description: Convert body from Markdown to HTML (set content_type input as text/html too) description: Convert body from Markdown to HTML (set content_type input as text/html too)
required: false required: false

37
main.js
View File

@ -1,7 +1,7 @@
const nodemailer = require("nodemailer") const nodemailer = require("nodemailer")
const core = require("@actions/core") const core = require("@actions/core")
const fs = require("fs") const fs = require("fs")
const showdown = require('showdown') const showdown = require("showdown")
function getBody(bodyOrFile, convertMarkdown) { function getBody(bodyOrFile, convertMarkdown) {
let body = bodyOrFile let body = bodyOrFile
@ -22,7 +22,7 @@ function getBody(bodyOrFile, convertMarkdown) {
} }
function getFrom(from, username) { function getFrom(from, username) {
if (from.match(/.+<.+@.+>/)) { if (from.match(/.+ <.+@.+>/)) {
return from return from
} }
@ -33,42 +33,47 @@ async function main() {
try { try {
const serverAddress = core.getInput("server_address", { required: true }) const serverAddress = core.getInput("server_address", { required: true })
const serverPort = core.getInput("server_port", { required: true }) const serverPort = core.getInput("server_port", { required: true })
const username = core.getInput("username", { required: true }) const username = core.getInput("username")
const password = core.getInput("password", { required: true }) const password = core.getInput("password")
const subject = core.getInput("subject", { required: true }) const subject = core.getInput("subject", { required: true })
const body = core.getInput("body", { required: true })
const from = core.getInput("from", { required: true }) const from = core.getInput("from", { required: true })
const to = core.getInput("to", { required: true }) const to = core.getInput("to", { required: true })
const secure = core.getInput("secure", { required: false })
const body = core.getInput("body", { required: false })
const htmlBody = core.getInput("html_body", { required: false })
const cc = core.getInput("cc", { required: false }) const cc = core.getInput("cc", { required: false })
const bcc = core.getInput("bcc", { required: false }) const bcc = core.getInput("bcc", { required: false })
const replyTo = core.getInput("reply_to", { required: false }) const replyTo = core.getInput("reply_to", { required: false })
const contentType = core.getInput("content_type", { required: true })
const attachments = core.getInput("attachments", { required: false }) const attachments = core.getInput("attachments", { required: false })
const convertMarkdown = core.getInput("convert_markdown", { required: false }) const convertMarkdown = core.getInput("convert_markdown", { required: false })
const ignoreCert = core.getInput("ignore_cert", { required: false }) const ignoreCert = core.getInput("ignore_cert", { required: false })
if (!username || !password) {
core.warning("Username and password not specified. You should only do this if you are using a self-hosted runner to access an on-premise mail server.")
}
const transport = nodemailer.createTransport({ const transport = nodemailer.createTransport({
host: serverAddress, host: serverAddress,
port: serverPort, auth: username && password ? {
secure: serverPort == "465",
auth: {
user: username, user: username,
pass: password, pass: password
}, } : undefined,
tls: ignoreCert ? { port: serverPort,
secure: secure == "true" ? true : serverPort == "465",
tls: ignoreCert == "true" ? {
rejectUnauthorized: false rejectUnauthorized: false
} : undefined } : undefined,
}) })
const info = await transport.sendMail({ const info = await transport.sendMail({
from: getFrom(from, username), from: getFrom(from, username),
to: to, to: to,
subject: subject,
cc: cc ? cc : undefined, cc: cc ? cc : undefined,
bcc: bcc ? bcc : undefined, bcc: bcc ? bcc : undefined,
replyTo: replyTo ? replyTo : undefined, replyTo: replyTo ? replyTo : undefined,
subject: subject, text: body ? getBody(body, false) : undefined,
text: contentType != "text/html" ? getBody(body, convertMarkdown) : undefined, html: htmlBody ? getBody(htmlBody, convertMarkdown) : undefined,
html: contentType == "text/html" ? getBody(body, convertMarkdown) : undefined,
attachments: attachments ? attachments.split(',').map(f => ({ path: f.trim() })) : undefined attachments: attachments ? attachments.split(',').map(f => ({ path: f.trim() })) : undefined
}) })
} catch (error) { } catch (error) {

14
package-lock.json generated
View File

@ -8,15 +8,15 @@
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.7",
"nodemailer": "^6.4.17", "nodemailer": "^6.4.17",
"showdown": "^1.9.1" "showdown": "^1.9.1"
} }
}, },
"node_modules/@actions/core": { "node_modules/@actions/core": {
"version": "1.2.6", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.7.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" "integrity": "sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig=="
}, },
"node_modules/ansi-regex": { "node_modules/ansi-regex": {
"version": "4.1.0", "version": "4.1.0",
@ -275,9 +275,9 @@
}, },
"dependencies": { "dependencies": {
"@actions/core": { "@actions/core": {
"version": "1.2.6", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.7.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" "integrity": "sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig=="
}, },
"ansi-regex": { "ansi-regex": {
"version": "4.1.0", "version": "4.1.0",

View File

@ -1,23 +1,8 @@
{ {
"name": "action-send-mail", "name": "action-send-mail",
"version": "1.0.0",
"description": "An action that simply sends a mail to multiple recipients.",
"main": "main.js", "main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dawidd6/action-send-mail.git"
},
"author": "dawidd6",
"license": "MIT",
"bugs": {
"url": "https://github.com/dawidd6/action-send-mail/issues"
},
"homepage": "https://github.com/dawidd6/action-send-mail#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.7",
"nodemailer": "^6.4.17", "nodemailer": "^6.4.17",
"showdown": "^1.9.1" "showdown": "^1.9.1"
} }