mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2024-11-10 05:51:07 +07:00
Attach multiple files to mail message
This commit is contained in:
parent
1733012f4d
commit
c2ca628a67
@ -21,6 +21,6 @@ An action that simply sends a mail to multiple recipients.
|
|||||||
from: Luke Skywalker # <user@example.com>
|
from: Luke Skywalker # <user@example.com>
|
||||||
# Optional content type (defaults to text/plain):
|
# Optional content type (defaults to text/plain):
|
||||||
content_type: text/html
|
content_type: text/html
|
||||||
# Optional single file attachment
|
# Optional attachments
|
||||||
attach_file: attachments.zip
|
attach_files: attachments.zip,git.diff,./dist/static/main.js
|
||||||
```
|
```
|
||||||
|
@ -33,8 +33,8 @@ inputs:
|
|||||||
description: Content-Type HTTP header (text/html or text/plain)
|
description: Content-Type HTTP header (text/html or text/plain)
|
||||||
required: false
|
required: false
|
||||||
default: text/plain
|
default: text/plain
|
||||||
attach_file:
|
attach_files:
|
||||||
description: File path that will be added to mail message attachments
|
description: File paths (separated with comma) that will be added to mail message attachments
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node12
|
||||||
|
16
main.js
16
main.js
@ -19,6 +19,16 @@ function get_from(from, username) {
|
|||||||
return `"${from}" <${username}>`
|
return `"${from}" <${username}>`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_attachments(attach_files) {
|
||||||
|
attach_files = attach_files.split(',')
|
||||||
|
let attachments = []
|
||||||
|
for (const attach_file of attach_files) {
|
||||||
|
attachments.push({path: attach_file})
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachments
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const server_address = core.getInput("server_address", { required: true })
|
const server_address = core.getInput("server_address", { required: true })
|
||||||
@ -30,7 +40,7 @@ async function main() {
|
|||||||
const to = core.getInput("to", { required: true })
|
const to = core.getInput("to", { required: true })
|
||||||
const from = core.getInput("from", { required: true })
|
const from = core.getInput("from", { required: true })
|
||||||
const content_type = core.getInput("content_type", { required: true })
|
const content_type = core.getInput("content_type", { required: true })
|
||||||
const attach_file = core.getInput("attach_file", { required: false })
|
const attach_files = core.getInput("attach_files", { required: false })
|
||||||
|
|
||||||
const transport = nodemailer.createTransport({
|
const transport = nodemailer.createTransport({
|
||||||
host: server_address,
|
host: server_address,
|
||||||
@ -48,9 +58,7 @@ async function main() {
|
|||||||
subject: subject,
|
subject: subject,
|
||||||
text: content_type != "text/html" ? get_body(body) : undefined,
|
text: content_type != "text/html" ? get_body(body) : undefined,
|
||||||
html: content_type == "text/html" ? get_body(body) : undefined,
|
html: content_type == "text/html" ? get_body(body) : undefined,
|
||||||
attachments: attach_file ? {
|
attachments: attach_files ? get_attachments(attach_files) : undefined
|
||||||
path: attach_file
|
|
||||||
} : undefined
|
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(info)
|
console.log(info)
|
||||||
|
Loading…
Reference in New Issue
Block a user