mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-01 12:43:15 +07:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
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:
|
||||||
|
@ -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
|
||||||
|
33
main.js
33
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 })
|
||||||
@ -92,14 +92,15 @@ async function main() {
|
|||||||
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 })
|
||||||
|
|
||||||
|
// 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 ? {
|
||||||
@ -116,14 +117,14 @@ async function main() {
|
|||||||
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