mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-03 21:53:15 +07:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
64262eed9b | |||
118894614c | |||
07d4810b3b | |||
924d1fedb2 | |||
602f9d1725 |
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
@ -58,3 +58,19 @@ jobs:
|
|||||||
attachments: ${{matrix.attachments}}
|
attachments: ${{matrix.attachments}}
|
||||||
convert_markdown: ${{matrix.convert_markdown}}
|
convert_markdown: ${{matrix.convert_markdown}}
|
||||||
priority: high
|
priority: high
|
||||||
|
|
||||||
|
url-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Send mail
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
connection_url: smtp+starttls://${{secrets.USERNAME}}:${{secrets.PASSWORD}}@${{secrets.ADDRESS}}/
|
||||||
|
subject: Plain body with connection_url
|
||||||
|
body: |
|
||||||
|
first line
|
||||||
|
second line
|
||||||
|
to: ${{github.event.pusher.email}}
|
||||||
|
from: github-actions
|
||||||
|
16
README.md
16
README.md
@ -16,10 +16,20 @@ Some features:
|
|||||||
- name: Send mail
|
- name: Send mail
|
||||||
uses: dawidd6/action-send-mail@v3
|
uses: dawidd6/action-send-mail@v3
|
||||||
with:
|
with:
|
||||||
# Required mail server address:
|
# Specify connection via URL (replaces server_address, server_port, secure,
|
||||||
|
# username and password)
|
||||||
|
#
|
||||||
|
# Format:
|
||||||
|
#
|
||||||
|
# * smtp://user:password@server:port
|
||||||
|
# * smtp+starttls://user:password@server:port
|
||||||
|
connection_url: ${{secrets.MAIL_CONNECTION}}
|
||||||
|
# Required mail server address if not connection_url:
|
||||||
server_address: smtp.gmail.com
|
server_address: smtp.gmail.com
|
||||||
# Required mail server port:
|
# Server port, default 25:
|
||||||
server_port: 465
|
server_port: 465
|
||||||
|
# Optional whether this connection use TLS (default is true if server_port is 465)
|
||||||
|
secure: true
|
||||||
# Optional (recommended): mail server username:
|
# Optional (recommended): mail server username:
|
||||||
username: ${{secrets.MAIL_USERNAME}}
|
username: ${{secrets.MAIL_USERNAME}}
|
||||||
# Optional (recommended) mail server password:
|
# Optional (recommended) mail server password:
|
||||||
@ -30,8 +40,6 @@ Some features:
|
|||||||
to: obiwan@example.com,yoda@example.com
|
to: obiwan@example.com,yoda@example.com
|
||||||
# Required sender full name (address can be skipped):
|
# Required sender full name (address can be skipped):
|
||||||
from: Luke Skywalker # <user@example.com>
|
from: Luke Skywalker # <user@example.com>
|
||||||
# Optional whether this connection use TLS (default is true if server_port is 465)
|
|
||||||
secure: true
|
|
||||||
# Optional plain body:
|
# Optional plain body:
|
||||||
body: Build job of ${{github.repository}} completed successfully!
|
body: Build job of ${{github.repository}} completed successfully!
|
||||||
# Optional HTML body read from file:
|
# Optional HTML body read from file:
|
||||||
|
12
action.yml
12
action.yml
@ -5,18 +5,19 @@ branding:
|
|||||||
icon: mail
|
icon: mail
|
||||||
color: blue
|
color: blue
|
||||||
inputs:
|
inputs:
|
||||||
|
connection_url:
|
||||||
|
description: Connection URL protocol://user:password@server:port, protocol can be smtp or smtp+starttls, replaces server_address, server_port, secure, username and password
|
||||||
server_address:
|
server_address:
|
||||||
description: SMTP server address
|
description: SMTP server address
|
||||||
required: true
|
|
||||||
server_port:
|
server_port:
|
||||||
description: SMTP server port
|
description: SMTP server port
|
||||||
required: true
|
default: "25"
|
||||||
|
secure:
|
||||||
|
description: Whether this connection use TLS (default is true if server_port is 465)
|
||||||
username:
|
username:
|
||||||
description: Authenticate as this user to SMTP server
|
description: Authenticate as this user to SMTP server
|
||||||
required: false
|
|
||||||
password:
|
password:
|
||||||
description: Authenticate with this password to SMTP server
|
description: Authenticate with this password to SMTP server
|
||||||
required: false
|
|
||||||
subject:
|
subject:
|
||||||
description: Subject of mail message
|
description: Subject of mail message
|
||||||
required: true
|
required: true
|
||||||
@ -26,9 +27,6 @@ inputs:
|
|||||||
from:
|
from:
|
||||||
description: Full name of mail sender (might be with an email address specified in <>)
|
description: Full name of mail sender (might be with an email address specified in <>)
|
||||||
required: true
|
required: true
|
||||||
secure:
|
|
||||||
description: Whether this connection use TLS (default is true if server_port is 465)
|
|
||||||
required: false
|
|
||||||
body:
|
body:
|
||||||
description: Body of mail message (might be a filename prefixed with file:// to read from)
|
description: Body of mail message (might be a filename prefixed with file:// to read from)
|
||||||
required: false
|
required: false
|
||||||
|
50
main.js
50
main.js
@ -39,14 +39,48 @@ async function getAttachments(attachments) {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const serverAddress = core.getInput("server_address", { required: true })
|
let serverAddress = core.getInput("server_address")
|
||||||
const serverPort = core.getInput("server_port", { required: true })
|
let serverPort = core.getInput("server_port")
|
||||||
const username = core.getInput("username")
|
let secure = core.getInput("secure")
|
||||||
const password = core.getInput("password")
|
let username = core.getInput("username")
|
||||||
|
let password = core.getInput("password")
|
||||||
|
|
||||||
|
if (!secure) {
|
||||||
|
secure = serverPort === "465" ? "true" : "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
const connectionUrl = core.getInput("connection_url")
|
||||||
|
if (connectionUrl) {
|
||||||
|
const url = new URL(connectionUrl)
|
||||||
|
switch (url.protocol) {
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported connection protocol '${url.protocol}'`)
|
||||||
|
case "smtp:":
|
||||||
|
serverPort = "25"
|
||||||
|
secure = "false"
|
||||||
|
break
|
||||||
|
case "smtp+starttls:":
|
||||||
|
serverPort = "465"
|
||||||
|
secure = "true"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (url.hostname) {
|
||||||
|
serverAddress = url.hostname
|
||||||
|
}
|
||||||
|
if (url.port) {
|
||||||
|
serverPort = url.port
|
||||||
|
}
|
||||||
|
if (url.username) {
|
||||||
|
username = unescape(url.username)
|
||||||
|
}
|
||||||
|
if (url.password) {
|
||||||
|
password = unescape(url.password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const subject = core.getInput("subject", { required: true })
|
const subject = core.getInput("subject", { required: true })
|
||||||
const from = core.getInput("from", { required: true })
|
const from = core.getInput("from", { required: true })
|
||||||
const to = core.getInput("to", { required: true })
|
const to = core.getInput("to", { required: true })
|
||||||
const secure = core.getInput("secure", { required: false })
|
|
||||||
const body = core.getInput("body", { required: false })
|
const body = core.getInput("body", { required: false })
|
||||||
const htmlBody = core.getInput("html_body", { required: false })
|
const htmlBody = core.getInput("html_body", { required: false })
|
||||||
const cc = core.getInput("cc", { required: false })
|
const cc = core.getInput("cc", { required: false })
|
||||||
@ -58,6 +92,10 @@ async function main() {
|
|||||||
const ignoreCert = core.getInput("ignore_cert", { required: false })
|
const ignoreCert = core.getInput("ignore_cert", { required: false })
|
||||||
const priority = core.getInput("priority", { required: false })
|
const priority = core.getInput("priority", { required: false })
|
||||||
|
|
||||||
|
if (!serverAddress) {
|
||||||
|
throw new Error("Server address must be specified")
|
||||||
|
}
|
||||||
|
|
||||||
if (!username || !password) {
|
if (!username || !password) {
|
||||||
core.warning("Username and password not specified. You should only do this if you are using a self-hosted runner to access an on-premise mail server.")
|
core.warning("Username and password not specified. You should only do this if you are using a self-hosted runner to access an on-premise mail server.")
|
||||||
}
|
}
|
||||||
@ -69,7 +107,7 @@ async function main() {
|
|||||||
pass: password
|
pass: password
|
||||||
} : undefined,
|
} : undefined,
|
||||||
port: serverPort,
|
port: serverPort,
|
||||||
secure: secure == "true" ? true : serverPort == "465",
|
secure: secure === "true",
|
||||||
tls: ignoreCert == "true" ? {
|
tls: ignoreCert == "true" ? {
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
} : undefined,
|
} : undefined,
|
||||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -7,7 +7,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.7",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/glob": "^0.2.1",
|
"@actions/glob": "^0.2.1",
|
||||||
"nodemailer": "^6.4.17",
|
"nodemailer": "^6.7.8",
|
||||||
"showdown": "^1.9.1"
|
"showdown": "^1.9.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -26,9 +26,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ansi-regex": {
|
"node_modules/ansi-regex": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz",
|
||||||
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
|
"integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
@ -158,9 +158,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nodemailer": {
|
"node_modules/nodemailer": {
|
||||||
"version": "6.6.2",
|
"version": "6.7.8",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.8.tgz",
|
||||||
"integrity": "sha512-YSzu7TLbI+bsjCis/TZlAXBoM4y93HhlIgo0P5oiA2ua9Z4k+E2Fod//ybIzdJxOlXGRcHIh/WaeCBehvxZb/Q==",
|
"integrity": "sha512-2zaTFGqZixVmTxpJRCFC+Vk5eGRd/fYtvIR+dl5u9QXLTQWGIf48x/JXvo58g9sa0bU6To04XUv554Paykum3g==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.0.0"
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
@ -326,9 +326,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ansi-regex": {
|
"ansi-regex": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz",
|
||||||
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg=="
|
"integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g=="
|
||||||
},
|
},
|
||||||
"ansi-styles": {
|
"ansi-styles": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.1",
|
||||||
@ -431,9 +431,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nodemailer": {
|
"nodemailer": {
|
||||||
"version": "6.6.2",
|
"version": "6.7.8",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.8.tgz",
|
||||||
"integrity": "sha512-YSzu7TLbI+bsjCis/TZlAXBoM4y93HhlIgo0P5oiA2ua9Z4k+E2Fod//ybIzdJxOlXGRcHIh/WaeCBehvxZb/Q=="
|
"integrity": "sha512-2zaTFGqZixVmTxpJRCFC+Vk5eGRd/fYtvIR+dl5u9QXLTQWGIf48x/JXvo58g9sa0bU6To04XUv554Paykum3g=="
|
||||||
},
|
},
|
||||||
"p-limit": {
|
"p-limit": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.7",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/glob": "^0.2.1",
|
"@actions/glob": "^0.2.1",
|
||||||
"nodemailer": "^6.4.17",
|
"nodemailer": "^6.7.8",
|
||||||
"showdown": "^1.9.1"
|
"showdown": "^1.9.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user