Revert "Add connection_url input parameter (#128)" (#130)

This reverts commit 602f9d1725.
This commit is contained in:
Dawid Dziurla 2022-09-01 23:36:08 +02:00 committed by GitHub
parent 602f9d1725
commit 924d1fedb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 61 deletions

View File

@ -16,20 +16,10 @@ Some features:
- name: Send mail - name: Send mail
uses: dawidd6/action-send-mail@v3 uses: dawidd6/action-send-mail@v3
with: with:
# Specify connection via URL (replaces server_address, server_port, secure, # Required mail server address:
# 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
# Server port, default 25: # Required mail server port:
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:
@ -40,6 +30,8 @@ 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:

View File

@ -5,19 +5,18 @@ 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
default: "25" required: true
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
@ -27,6 +26,9 @@ 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
View File

@ -39,48 +39,14 @@ async function getAttachments(attachments) {
async function main() { async function main() {
try { try {
let serverAddress = core.getInput("server_address") const serverAddress = core.getInput("server_address", { required: true })
let serverPort = core.getInput("server_port") const serverPort = core.getInput("server_port", { required: true })
let secure = core.getInput("secure") const username = core.getInput("username")
let username = core.getInput("username") const password = core.getInput("password")
let password = core.getInput("password")
if (!secure) {
secure = serverPort === "465"
}
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 })
@ -92,10 +58,6 @@ 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.")
} }
@ -107,7 +69,7 @@ async function main() {
pass: password pass: password
} : undefined, } : undefined,
port: serverPort, port: serverPort,
secure: secure == "true", secure: secure == "true" ? true : serverPort == "465",
tls: ignoreCert == "true" ? { tls: ignoreCert == "true" ? {
rejectUnauthorized: false rejectUnauthorized: false
} : undefined, } : undefined,