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:
@ -39,11 +44,11 @@ An action that simply sends a mail to multiple recipients.
### Gmail
Gmail security settings may cause this Action to fail. This failure may involve a message in the GitHub Actions details about access being denied and an email from Google to the email account being used about a sign-in being blocked and why.
Gmail security settings may cause this Action to fail. This failure may involve a message in the GitHub Actions details about access being denied and an email from Google to the email account being used about a sign-in being blocked and why.
Changes in Gmail settings may be necessary to get this action to work.
1. Google treats this method of using email as a "Less Secure App". However, "Less Secure Apps" can be enabled in Google profile settings. There doesn't appear to be a static link for this, but if you go to Google profile settings while signed-in and type "less secure apps" into the search bar, the appropriate instructions will come up.
2. IMAP needs to be enabled in Gmail settings as described here: https://support.google.com/mail/answer/7126229?hl=en
1. Google treats this method of using email as a "Less Secure App". However, "Less Secure Apps" can be enabled in Google profile settings. There doesn't appear to be a static link for this, but if you go to Google profile settings while signed-in and type "less secure apps" into the search bar, the appropriate instructions will come up.
2. IMAP needs to be enabled in Gmail settings as described here: https://support.google.com/mail/answer/7126229?hl=en
3. If the Gmail account you're trying to use in this Action is already 2FA (Two Factor Authentication) enabled, the 2FA password will need to be provided as well, which isn't included in the default template.
Users who have had problems have reported success by doing each of these three steps or by doing the first two steps and using a Gmail account that didn't have 2FA enabled.
Users who have had problems have reported success by doing each of these three steps or by doing the first two steps and using a Gmail account that didn't have 2FA enabled.

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

12
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 })
@ -59,16 +59,16 @@ async function main() {
rejectUnauthorized: false
} : undefined
})
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) {