mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-01 20:53:14 +07:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
dc13c734ff | |||
48476814b0 | |||
e3f3ba4f86 | |||
19516a4a58 | |||
3c0bbc53ef | |||
6d8218d1d2 | |||
657e138a0a | |||
874d3db0a9 |
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
|||||||
<p>Paragraph</p>
|
<p>Paragraph</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
- subject: Plain body (Markdown)
|
- subject: file://testdata/subject.txt
|
||||||
convert_markdown: true
|
convert_markdown: true
|
||||||
body: file://README.md
|
body: file://README.md
|
||||||
- subject: HTML body (Markdown)
|
- subject: HTML body (Markdown)
|
||||||
@ -42,7 +42,7 @@ jobs:
|
|||||||
html_body: file://README.md
|
html_body: file://README.md
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
- name: Send mail
|
- name: Send mail
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@ -63,7 +63,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
- name: Send mail
|
- name: Send mail
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
@ -60,6 +60,10 @@ Some features:
|
|||||||
attachments: attachments.zip,git.diff,./dist/static/*.js
|
attachments: attachments.zip,git.diff,./dist/static/*.js
|
||||||
# Optional priority: 'high', 'normal' (default) or 'low'
|
# Optional priority: 'high', 'normal' (default) or 'low'
|
||||||
priority: low
|
priority: low
|
||||||
|
# Optional nodemailerlog: true/false
|
||||||
|
nodemailerlog: false
|
||||||
|
# Optional nodemailerdebug: true/false if true lognodem will also be set true
|
||||||
|
nodemailerdebug: false
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
@ -23,7 +23,7 @@ inputs:
|
|||||||
required: true
|
required: true
|
||||||
to:
|
to:
|
||||||
description: Recipients mail addresses (separated with comma)
|
description: Recipients mail addresses (separated with comma)
|
||||||
required: true
|
required: false
|
||||||
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
|
||||||
@ -57,6 +57,12 @@ inputs:
|
|||||||
priority:
|
priority:
|
||||||
description: Set Priority level for the mail message to 'high', 'normal' (default) or 'low'
|
description: Set Priority level for the mail message to 'high', 'normal' (default) or 'low'
|
||||||
required: false
|
required: false
|
||||||
|
nodemailerlog:
|
||||||
|
description: Log option for nodemailer
|
||||||
|
required: false
|
||||||
|
nodemailerdebug:
|
||||||
|
description: Debug option for nodemailer
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: node16
|
using: node16
|
||||||
main: main.js
|
main: main.js
|
||||||
|
37
main.js
37
main.js
@ -5,22 +5,22 @@ const fs = require("fs")
|
|||||||
const showdown = require("showdown")
|
const showdown = require("showdown")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
|
|
||||||
function getBody(bodyOrFile, convertMarkdown) {
|
function getText(textOrFile, convertMarkdown) {
|
||||||
let body = bodyOrFile
|
let text = textOrFile
|
||||||
|
|
||||||
// Read body from file
|
// Read text from file
|
||||||
if (bodyOrFile.startsWith("file://")) {
|
if (textOrFile.startsWith("file://")) {
|
||||||
const file = bodyOrFile.replace("file://", "")
|
const file = textOrFile.replace("file://", "")
|
||||||
body = fs.readFileSync(file, "utf8")
|
text = fs.readFileSync(file, "utf8")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Markdown to HTML
|
// Convert Markdown to HTML
|
||||||
if (convertMarkdown) {
|
if (convertMarkdown) {
|
||||||
const converter = new showdown.Converter()
|
const converter = new showdown.Converter()
|
||||||
body = converter.makeHtml(body)
|
text = converter.makeHtml(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
return body
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFrom(from, username) {
|
function getFrom(from, username) {
|
||||||
@ -80,7 +80,7 @@ async function main() {
|
|||||||
|
|
||||||
const subject = core.getInput("subject", { required: true })
|
const subject = core.getInput("subject", { 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: false })
|
||||||
const body = core.getInput("body", { required: false })
|
const body = core.getInput("body", { required: false })
|
||||||
const htmlBody = core.getInput("html_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 })
|
||||||
@ -91,15 +91,18 @@ async function main() {
|
|||||||
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 })
|
||||||
const priority = core.getInput("priority", { required: false })
|
const priority = core.getInput("priority", { required: false })
|
||||||
|
const nodemailerlog = core.getInput("nodemailerlog", { required: false })
|
||||||
|
const nodemailerdebug = core.getInput("nodemailerdebug", { required: false })
|
||||||
|
|
||||||
|
// if neither to, cc or bcc is provided, throw error
|
||||||
|
if (!to && !cc && !bcc) {
|
||||||
|
throw new Error("At least one of 'to', 'cc' or 'bcc' must be specified")
|
||||||
|
}
|
||||||
|
|
||||||
if (!serverAddress) {
|
if (!serverAddress) {
|
||||||
throw new Error("Server address must be specified")
|
throw new Error("Server address must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
auth: username && password ? {
|
auth: username && password ? {
|
||||||
@ -111,19 +114,21 @@ async function main() {
|
|||||||
tls: ignoreCert == "true" ? {
|
tls: ignoreCert == "true" ? {
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
} : undefined,
|
} : undefined,
|
||||||
|
logger: nodemailerdebug == "true" ? true : nodemailerlog,
|
||||||
|
debug: nodemailerdebug,
|
||||||
})
|
})
|
||||||
|
|
||||||
const info = await transport.sendMail({
|
const info = await transport.sendMail({
|
||||||
from: getFrom(from, username),
|
from: getFrom(from, username),
|
||||||
to: to,
|
to: to,
|
||||||
subject: subject,
|
subject: getText(subject, false),
|
||||||
cc: cc ? cc : undefined,
|
cc: cc ? cc : undefined,
|
||||||
bcc: bcc ? bcc : undefined,
|
bcc: bcc ? bcc : undefined,
|
||||||
replyTo: replyTo ? replyTo : undefined,
|
replyTo: replyTo ? replyTo : undefined,
|
||||||
inReplyTo: inReplyTo ? inReplyTo : undefined,
|
inReplyTo: inReplyTo ? inReplyTo : undefined,
|
||||||
references: inReplyTo ? inReplyTo : undefined,
|
references: inReplyTo ? inReplyTo : undefined,
|
||||||
text: body ? getBody(body, false) : undefined,
|
text: body ? getText(body, false) : undefined,
|
||||||
html: htmlBody ? getBody(htmlBody, convertMarkdown) : undefined,
|
html: htmlBody ? getText(htmlBody, convertMarkdown) : undefined,
|
||||||
priority: priority ? priority : undefined,
|
priority: priority ? priority : undefined,
|
||||||
attachments: attachments ? (await getAttachments(attachments)) : undefined,
|
attachments: attachments ? (await getAttachments(attachments)) : undefined,
|
||||||
})
|
})
|
||||||
|
32
package-lock.json
generated
32
package-lock.json
generated
@ -7,8 +7,8 @@
|
|||||||
"name": "action-send-mail",
|
"name": "action-send-mail",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.7",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/glob": "^0.2.1",
|
"@actions/glob": "^0.4.0",
|
||||||
"nodemailer": "^6.7.8",
|
"nodemailer": "^6.9.1",
|
||||||
"showdown": "^1.9.1"
|
"showdown": "^1.9.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -22,11 +22,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/glob": {
|
"node_modules/@actions/glob": {
|
||||||
"version": "0.2.1",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.4.0.tgz",
|
||||||
"integrity": "sha512-OqseGbxR8vVikg6rfdKST21GX3QYGq2Nz7/gX3UxZb2Mw1ujJ2S3U5CsYUvYHwxbYguU+HNhfE3930oo5nprXQ==",
|
"integrity": "sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.9.1",
|
||||||
"minimatch": "^3.0.4"
|
"minimatch": "^3.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -171,9 +171,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nodemailer": {
|
"node_modules/nodemailer": {
|
||||||
"version": "6.8.0",
|
"version": "6.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
|
||||||
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==",
|
"integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.0.0"
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
@ -350,11 +350,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/glob": {
|
"@actions/glob": {
|
||||||
"version": "0.2.1",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.4.0.tgz",
|
||||||
"integrity": "sha512-OqseGbxR8vVikg6rfdKST21GX3QYGq2Nz7/gX3UxZb2Mw1ujJ2S3U5CsYUvYHwxbYguU+HNhfE3930oo5nprXQ==",
|
"integrity": "sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.9.1",
|
||||||
"minimatch": "^3.0.4"
|
"minimatch": "^3.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -472,9 +472,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nodemailer": {
|
"nodemailer": {
|
||||||
"version": "6.8.0",
|
"version": "6.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
|
||||||
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ=="
|
"integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA=="
|
||||||
},
|
},
|
||||||
"p-limit": {
|
"p-limit": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.7",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/glob": "^0.2.1",
|
"@actions/glob": "^0.4.0",
|
||||||
"nodemailer": "^6.7.8",
|
"nodemailer": "^6.9.1",
|
||||||
"showdown": "^1.9.1"
|
"showdown": "^1.9.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
testdata/subject.txt
vendored
Normal file
1
testdata/subject.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Plain body (Markdown)
|
Reference in New Issue
Block a user