mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2024-12-25 10:33:07 +07:00
Support reading the subject from a file. (#173)
Allows dynamic subjects to be generated at action runtime (e.g., "Foobar version 1.2.3 is released", where 1.2.3 is not known at action config time). Leverages the existing file:// support for body, but renames getBody to getText, in keeping with this expanded role.
This commit is contained in:
parent
6d8218d1d2
commit
3c0bbc53ef
2
.github/workflows/test.yml
vendored
2
.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)
|
||||||
|
22
main.js
22
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) {
|
||||||
@ -116,14 +116,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,
|
||||||
})
|
})
|
||||||
|
1
testdata/subject.txt
vendored
Normal file
1
testdata/subject.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Plain body (Markdown)
|
Loading…
Reference in New Issue
Block a user