22 Commits

Author SHA1 Message Date
c550a7182d workflows: test sending mails with attachments 2020-04-07 10:38:01 +02:00
b75f3336d9 README: colon 2020-04-07 10:36:16 +02:00
0e3a58617a Merge pull request #6 from sturman/attachment
Add option to add attachments to mail message
2020-04-07 10:33:41 +02:00
3eb5d684cd Apply field description suggested by author 2020-04-07 11:32:14 +03:00
02fea7e898 Refactor parse attachments. Rename field 2020-04-07 11:30:45 +03:00
c2ca628a67 Attach multiple files to mail message 2020-04-07 11:14:31 +03:00
1733012f4d Add example in doc 2020-04-07 09:55:36 +03:00
a5cba0b6c1 Do not add attachment in case it's not specified 2020-04-07 09:50:06 +03:00
d4b4fe8144 Add possibility to attach a file to mail 2020-04-07 09:46:19 +03:00
67e2095a53 README: point to a tag instead of master branch 2020-03-29 23:16:00 +02:00
c6d4807c13 action: mail -> email 2020-03-27 10:24:26 +01:00
4586381ad5 action: email -> mail 2020-03-27 10:20:42 +01:00
b961a9185a workflows: without address in from input 2020-03-27 10:06:02 +01:00
ac180b7bd9 action: more descriptive descriptions 2020-03-27 09:52:00 +01:00
56a64662b4 README: optional address in from input 2020-03-25 16:30:22 +01:00
296e585baf workflows: use secret FROM 2020-03-25 16:25:22 +01:00
1cf295c810 workflows: specify email address in from input 2020-03-25 16:20:29 +01:00
f00590fc1a main: allow two variants of from 2020-03-25 16:18:35 +01:00
b27f0d4766 main: pass from input as is 2020-03-25 16:06:11 +01:00
a4a1b1f1d5 workflows: checkout code 2020-03-25 15:58:47 +01:00
ce64ae4df1 workflows: send only to pusher 2020-03-25 15:50:42 +01:00
5b4b61f0c4 workflows: max 1 parallel job can run 2020-03-24 14:09:19 +01:00
4 changed files with 29 additions and 10 deletions

View File

@ -6,6 +6,7 @@ jobs:
main:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
content_type:
- text/plain
@ -13,6 +14,7 @@ jobs:
include:
- content_type: text/plain
body: file://README.md
attachments: action.yml
- content_type: text/html
body: |
<!DOCTYPE html>
@ -22,8 +24,9 @@ jobs:
<p>Paragraph</p>
</body>
</html>
attachments: package.json,package-lock.json
steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v1
- name: Send mail
uses: ./
@ -34,6 +37,7 @@ jobs:
password: ${{secrets.PASSWORD}}
subject: ${{github.repository}}
body: ${{matrix.body}}
to: ${{github.event.pusher.email}},${{secrets.USERNAME}}
to: ${{github.event.pusher.email}}
from: github-actions
content_type: ${{matrix.content_type}}
content_type: ${{matrix.content_type}}
attachments: ${{matrix.attachments}}

View File

@ -6,7 +6,7 @@ An action that simply sends a mail to multiple recipients.
```yaml
- name: Send mail
uses: dawidd6/action-send-mail@master
uses: dawidd6/action-send-mail@v2
with:
server_address: smtp.gmail.com
server_port: 465
@ -18,7 +18,9 @@ An action that simply sends a mail to multiple recipients.
# Read file contents as body:
body: file://README.md
to: obiwan@tatooine.com,yoda@dagobah.com
from: Luke Skywalker
from: Luke Skywalker # <user@example.com>
# Optional content type (defaults to text/plain):
content_type: text/html
# Optional attachments:
attachments: attachments.zip,git.diff,./dist/static/main.js
```

View File

@ -1,5 +1,5 @@
name: Send email
description: Send mail to multiple recipients
description: Send an email to multiple recipients
author: dawidd6
branding:
icon: mail
@ -21,18 +21,21 @@ inputs:
description: Subject of mail message
required: true
body:
description: Body of mail message (might be a filename to read from)
description: Body of mail message (might be a filename prefixed with file:// to read from)
required: true
to:
description: Recipients mail addresses (separated with comma)
required: true
from:
description: Full name of mail sender
description: Full name of mail sender (might be with an email address specified in <>)
required: true
content_type:
description: Content-Type HTTP header (text/html or text/plain)
required: false
default: text/plain
attachments:
description: Files that will be added to mail message attachments (separated with comma)
required: false
runs:
using: node12
main: main.js

14
main.js
View File

@ -11,6 +11,14 @@ function get_body(body) {
return body
}
function get_from(from, username) {
if (from.match(/.+<.+@.+>/)) {
return from
}
return `"${from}" <${username}>`
}
async function main() {
try {
const server_address = core.getInput("server_address", { required: true })
@ -22,6 +30,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 attachments = core.getInput("attachments", { required: false })
const transport = nodemailer.createTransport({
host: server_address,
@ -34,11 +43,12 @@ async function main() {
})
const info = await transport.sendMail({
from: `"${from}" <${username}>`,
from: get_from(from, username),
to: to,
subject: subject,
text: content_type != "text/html" ? get_body(body) : undefined,
html: content_type == "text/html" ? get_body(body) : undefined,
attachments: attachments ? attachments.split(',').map(f => ({ path: f.trim() })) : undefined
})
console.log(info)
@ -47,4 +57,4 @@ async function main() {
}
}
main()
main()