support multipart email (#48)

Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
This commit is contained in:
Jiacai Liu 2021-04-25 22:11:54 +08:00 committed by GitHub
parent 32390e9a18
commit c938b3cb85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 26 deletions

View File

@ -8,27 +8,32 @@ An action that simply sends a mail to multiple recipients.
- name: Send mail
uses: dawidd6/action-send-mail@v2
with:
# Required mail server address:
server_address: smtp.gmail.com
# Required mail server port:
server_port: 465
# Required mail server username:
username: ${{secrets.MAIL_USERNAME}}
# Required mail server password:
password: ${{secrets.MAIL_PASSWORD}}
# Required mail subject:
subject: Github Actions job result
# Literal body:
body: Build job of ${{github.repository}} completed successfully!
# Read file contents as body:
body: file://README.md
# Required recipients' addresses:
to: obiwan@example.com,yoda@example.com
# Required sender information (address can be skipped):
from: Luke Skywalker # <user@example.com>
# Optional carbon copy recipients
# Optional plain body:
body: Build job of ${{github.repository}} completed successfully!
# Optional HTML body read from file:
html_body: file://README.html
# Optional carbon copy recipients:
cc: kyloren@example.com,leia@example.com
# Optional blind carbon copy recipients
# Optional blind carbon copy recipients:
bcc: r2d2@example.com,hansolo@example.com
# Optional recipient of the email response
# Optional recipient of the email response:
reply_to: luke@example.com
# Optional unsigned/invalid certificates allowance:
ignore_cert: true
# Optional content type (defaults to text/plain):
content_type: text/html
# Optional converting Markdown to HTML (set content_type to text/html too):
convert_markdown: true
# Optional attachments:

View File

@ -20,15 +20,18 @@ inputs:
subject:
description: Subject of mail message
required: true
body:
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 (might be with an email address specified in <>)
required: true
body:
description: Body of mail message (might be a filename prefixed with file:// to read from)
required: false
html_body:
description: HTML body of mail message (might be a filename prefixed with file:// to read from)
required: false
cc:
description: Carbon copy recipients (separated with comma)
required: false
@ -41,10 +44,6 @@ inputs:
ignore_cert:
description: Allow unsigned/invalid certificates
required: false
content_type:
description: Content-Type HTTP header (text/html or text/plain)
required: false
default: text/plain
convert_markdown:
description: Convert body from Markdown to HTML (set content_type input as text/html too)
required: false

10
main.js
View File

@ -36,13 +36,13 @@ async function main() {
const username = core.getInput("username", { required: true })
const password = core.getInput("password", { required: true })
const subject = core.getInput("subject", { required: true })
const body = core.getInput("body", { required: true })
const from = core.getInput("from", { required: true })
const to = core.getInput("to", { required: true })
const body = core.getInput("body", { required: false })
const htmlBody = core.getInput("html_body", { required: false })
const cc = core.getInput("cc", { required: false })
const bcc = core.getInput("bcc", { required: false })
const replyTo = core.getInput("reply_to", { required: false })
const contentType = core.getInput("content_type", { required: true })
const attachments = core.getInput("attachments", { required: false })
const convertMarkdown = core.getInput("convert_markdown", { required: false })
const ignoreCert = core.getInput("ignore_cert", { required: false })
@ -63,12 +63,12 @@ async function main() {
const info = await transport.sendMail({
from: getFrom(from, username),
to: to,
subject: subject,
cc: cc ? cc : undefined,
bcc: bcc ? bcc : undefined,
replyTo: replyTo ? replyTo : undefined,
subject: subject,
text: contentType != "text/html" ? getBody(body, convertMarkdown) : undefined,
html: contentType == "text/html" ? getBody(body, convertMarkdown) : undefined,
text: body ? getBody(body, convertMarkdown) : undefined,
html: htmlBody ? getBody(htmlBody, convertMarkdown) : undefined,
attachments: attachments ? attachments.split(',').map(f => ({ path: f.trim() })) : undefined
})
} catch (error) {