diff --git a/README.md b/README.md index 1a2f66dc..e59041d4 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,6 @@ An action that simply sends a mail to multiple recipients. from: Luke Skywalker # # Optional content type (defaults to text/plain): content_type: text/html - # Optional single file attachment - attach_file: attachments.zip + # Optional attachments + attach_files: attachments.zip,git.diff,./dist/static/main.js ``` diff --git a/action.yml b/action.yml index d011e2c1..1e1a5e69 100644 --- a/action.yml +++ b/action.yml @@ -33,8 +33,8 @@ inputs: description: Content-Type HTTP header (text/html or text/plain) required: false default: text/plain - attach_file: - description: File path that will be added to mail message attachments + attach_files: + description: File paths (separated with comma) that will be added to mail message attachments required: false runs: using: node12 diff --git a/main.js b/main.js index d758ee52..eb54f673 100644 --- a/main.js +++ b/main.js @@ -19,6 +19,16 @@ function get_from(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() { try { const server_address = core.getInput("server_address", { required: true }) @@ -30,7 +40,7 @@ async function main() { const to = core.getInput("to", { required: true }) const from = core.getInput("from", { 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({ host: server_address, @@ -48,9 +58,7 @@ async function main() { subject: subject, text: content_type != "text/html" ? get_body(body) : undefined, html: content_type == "text/html" ? get_body(body) : undefined, - attachments: attach_file ? { - path: attach_file - } : undefined + attachments: attach_files ? get_attachments(attach_files) : undefined }) console.log(info)