mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-01 04:33:16 +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>
|
||||
</body>
|
||||
</html>
|
||||
- subject: Plain body (Markdown)
|
||||
- subject: file://testdata/subject.txt
|
||||
convert_markdown: true
|
||||
body: file://README.md
|
||||
- subject: HTML body (Markdown)
|
||||
@ -42,7 +42,7 @@ jobs:
|
||||
html_body: file://README.md
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
- name: Send mail
|
||||
uses: ./
|
||||
with:
|
||||
@ -63,7 +63,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
- name: Send mail
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -23,7 +23,7 @@ inputs:
|
||||
required: true
|
||||
to:
|
||||
description: Recipients mail addresses (separated with comma)
|
||||
required: true
|
||||
required: false
|
||||
from:
|
||||
description: Full name of mail sender (might be with an email address specified in <>)
|
||||
required: true
|
||||
|
33
main.js
33
main.js
@ -5,22 +5,22 @@ const fs = require("fs")
|
||||
const showdown = require("showdown")
|
||||
const path = require("path")
|
||||
|
||||
function getBody(bodyOrFile, convertMarkdown) {
|
||||
let body = bodyOrFile
|
||||
function getText(textOrFile, convertMarkdown) {
|
||||
let text = textOrFile
|
||||
|
||||
// Read body from file
|
||||
if (bodyOrFile.startsWith("file://")) {
|
||||
const file = bodyOrFile.replace("file://", "")
|
||||
body = fs.readFileSync(file, "utf8")
|
||||
// Read text from file
|
||||
if (textOrFile.startsWith("file://")) {
|
||||
const file = textOrFile.replace("file://", "")
|
||||
text = fs.readFileSync(file, "utf8")
|
||||
}
|
||||
|
||||
// Convert Markdown to HTML
|
||||
if (convertMarkdown) {
|
||||
const converter = new showdown.Converter()
|
||||
body = converter.makeHtml(body)
|
||||
text = converter.makeHtml(text)
|
||||
}
|
||||
|
||||
return body
|
||||
return text
|
||||
}
|
||||
|
||||
function getFrom(from, username) {
|
||||
@ -80,7 +80,7 @@ async function main() {
|
||||
|
||||
const subject = core.getInput("subject", { 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 htmlBody = core.getInput("html_body", { 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 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) {
|
||||
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({
|
||||
host: serverAddress,
|
||||
auth: username && password ? {
|
||||
@ -116,14 +117,14 @@ async function main() {
|
||||
const info = await transport.sendMail({
|
||||
from: getFrom(from, username),
|
||||
to: to,
|
||||
subject: subject,
|
||||
subject: getText(subject, false),
|
||||
cc: cc ? cc : undefined,
|
||||
bcc: bcc ? bcc : undefined,
|
||||
replyTo: replyTo ? replyTo : undefined,
|
||||
inReplyTo: inReplyTo ? inReplyTo : undefined,
|
||||
references: inReplyTo ? inReplyTo : undefined,
|
||||
text: body ? getBody(body, false) : undefined,
|
||||
html: htmlBody ? getBody(htmlBody, convertMarkdown) : undefined,
|
||||
text: body ? getText(body, false) : undefined,
|
||||
html: htmlBody ? getText(htmlBody, convertMarkdown) : undefined,
|
||||
priority: priority ? priority : 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",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.7",
|
||||
"@actions/glob": "^0.2.1",
|
||||
"nodemailer": "^6.7.8",
|
||||
"@actions/glob": "^0.4.0",
|
||||
"nodemailer": "^6.9.1",
|
||||
"showdown": "^1.9.1"
|
||||
}
|
||||
},
|
||||
@ -22,11 +22,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/glob": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.2.1.tgz",
|
||||
"integrity": "sha512-OqseGbxR8vVikg6rfdKST21GX3QYGq2Nz7/gX3UxZb2Mw1ujJ2S3U5CsYUvYHwxbYguU+HNhfE3930oo5nprXQ==",
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.4.0.tgz",
|
||||
"integrity": "sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/core": "^1.9.1",
|
||||
"minimatch": "^3.0.4"
|
||||
}
|
||||
},
|
||||
@ -171,9 +171,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "6.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
||||
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==",
|
||||
"version": "6.9.1",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
|
||||
"integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
@ -350,11 +350,11 @@
|
||||
}
|
||||
},
|
||||
"@actions/glob": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.2.1.tgz",
|
||||
"integrity": "sha512-OqseGbxR8vVikg6rfdKST21GX3QYGq2Nz7/gX3UxZb2Mw1ujJ2S3U5CsYUvYHwxbYguU+HNhfE3930oo5nprXQ==",
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.4.0.tgz",
|
||||
"integrity": "sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==",
|
||||
"requires": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/core": "^1.9.1",
|
||||
"minimatch": "^3.0.4"
|
||||
}
|
||||
},
|
||||
@ -472,9 +472,9 @@
|
||||
}
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
||||
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ=="
|
||||
"version": "6.9.1",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
|
||||
"integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA=="
|
||||
},
|
||||
"p-limit": {
|
||||
"version": "2.3.0",
|
||||
|
@ -3,8 +3,8 @@
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.7",
|
||||
"@actions/glob": "^0.2.1",
|
||||
"nodemailer": "^6.7.8",
|
||||
"@actions/glob": "^0.4.0",
|
||||
"nodemailer": "^6.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