13 Commits

Author SHA1 Message Date
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
6 changed files with 75 additions and 48 deletions

View File

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

View File

@ -2,35 +2,61 @@
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
```yaml
- name: Send mail
uses: dawidd6/action-send-mail@v2
uses: dawidd6/action-send-mail@v3
with:
# Required mail server address:
server_address: smtp.gmail.com
# Required mail server port:
server_port: 465
# Required mail server username:
username: ${{secrets.MAIL_USERNAME}}
# Required mail server password:
password: ${{secrets.MAIL_PASSWORD}}
# Required mail subject:
subject: Github Actions job result
# Literal body:
body: Build job of ${{github.repository}} completed successfully!
# Read file contents as body:
body: file://README.md
# Required recipients' addresses:
to: obiwan@example.com,yoda@example.com
# Required sender full name (address can be skipped):
from: Luke Skywalker # <user@example.com>
# Optional carbon copy recipients
# 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
# Optional blind carbon copy recipients
# Optional blind carbon copy recipients:
bcc: r2d2@example.com,hansolo@example.com
# Optional recipient of the email response
# Optional recipient of the email response:
reply_to: luke@example.com
# Optional unsigned/invalid certificates allowance:
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):
convert_markdown: true
# Optional attachments:
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.

View File

@ -20,15 +20,18 @@ inputs:
subject:
description: Subject of mail message
required: true
body:
description: Body of mail message (might be a filename prefixed with file:// to read from)
required: true
to:
description: Recipients mail addresses (separated with comma)
required: true
from:
description: Full name of mail sender (might be with an email address specified in <>)
required: true
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:
description: Carbon copy recipients (separated with comma)
required: false
@ -41,10 +44,6 @@ inputs:
ignore_cert:
description: Allow unsigned/invalid certificates
required: false
content_type:
description: Content-Type HTTP header (text/html or text/plain)
required: false
default: text/plain
convert_markdown:
description: Convert body from Markdown to HTML (set content_type input as text/html too)
required: false

14
main.js
View File

@ -1,7 +1,7 @@
const nodemailer = require("nodemailer")
const core = require("@actions/core")
const fs = require("fs")
const showdown = require('showdown')
const showdown = require("showdown")
function getBody(bodyOrFile, convertMarkdown) {
let body = bodyOrFile
@ -22,7 +22,7 @@ function getBody(bodyOrFile, convertMarkdown) {
}
function getFrom(from, username) {
if (from.match(/.+<.+@.+>/)) {
if (from.match(/.+ <.+@.+>/)) {
return from
}
@ -36,13 +36,13 @@ async function main() {
const username = core.getInput("username", { required: true })
const password = core.getInput("password", { required: true })
const subject = core.getInput("subject", { required: true })
const body = core.getInput("body", { required: true })
const from = core.getInput("from", { required: true })
const to = core.getInput("to", { required: true })
const body = core.getInput("body", { required: false })
const htmlBody = core.getInput("html_body", { required: false })
const cc = core.getInput("cc", { required: false })
const bcc = core.getInput("bcc", { 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 convertMarkdown = core.getInput("convert_markdown", { required: false })
const ignoreCert = core.getInput("ignore_cert", { required: false })
@ -63,12 +63,12 @@ async function main() {
const info = await transport.sendMail({
from: getFrom(from, username),
to: to,
subject: subject,
cc: cc ? cc : undefined,
bcc: bcc ? bcc : undefined,
replyTo: replyTo ? replyTo : undefined,
subject: subject,
text: contentType != "text/html" ? getBody(body, convertMarkdown) : undefined,
html: contentType == "text/html" ? getBody(body, convertMarkdown) : undefined,
text: body ? getBody(body, false) : undefined,
html: htmlBody ? getBody(htmlBody, convertMarkdown) : undefined,
attachments: attachments ? attachments.split(',').map(f => ({ path: f.trim() })) : undefined
})
} catch (error) {

14
package-lock.json generated
View File

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

View File

@ -17,7 +17,7 @@
},
"homepage": "https://github.com/dawidd6/action-send-mail#readme",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/core": "^1.2.7",
"nodemailer": "^6.4.17",
"showdown": "^1.9.1"
}