mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-01 20:53:14 +07:00
Add connection_url input parameter (#128)
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 Closes: #127 Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com> Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
This commit is contained in:
50
main.js
50
main.js
@ -39,14 +39,48 @@ async function getAttachments(attachments) {
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const serverAddress = core.getInput("server_address", { required: true })
|
||||
const serverPort = core.getInput("server_port", { required: true })
|
||||
const username = core.getInput("username")
|
||||
const password = core.getInput("password")
|
||||
let serverAddress = core.getInput("server_address")
|
||||
let serverPort = core.getInput("server_port")
|
||||
let secure = core.getInput("secure")
|
||||
let username = core.getInput("username")
|
||||
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 from = core.getInput("from", { required: true })
|
||||
const to = core.getInput("to", { required: true })
|
||||
const secure = core.getInput("secure", { required: false })
|
||||
const body = core.getInput("body", { required: false })
|
||||
const htmlBody = core.getInput("html_body", { 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 priority = core.getInput("priority", { required: false })
|
||||
|
||||
if (!serverAddress) {
|
||||
throw new Error("Server address must be specified");
|
||||
}
|
||||
|
||||
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.")
|
||||
}
|
||||
@ -69,7 +107,7 @@ async function main() {
|
||||
pass: password
|
||||
} : undefined,
|
||||
port: serverPort,
|
||||
secure: secure == "true" ? true : serverPort == "465",
|
||||
secure: secure == "true",
|
||||
tls: ignoreCert == "true" ? {
|
||||
rejectUnauthorized: false
|
||||
} : undefined,
|
||||
|
Reference in New Issue
Block a user