mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-09-17 09:06:48 +07:00
Take the proxy from smtp_proxy instead of HTTP_PROXY (#316)
* Take the proxy from SMTP_PROXY instead of HTTP_PROXY HTTP_PROXY says how to reach the web, and on a self-hosted runner it is routinely set machine-wide while the mail server has to be reached directly. Sending SMTP through it makes such a proxy refuse the connection, and there was no way to opt out. Read the protocol-specific SMTP_PROXY instead, and honour NO_PROXY so a host can be exempted from it. Co-Authored-By: Claude (Opus 5) <noreply@anthropic.com> * Accept smtps_proxy too, and prefer the lowercase spelling curl reads the lowercase name first and falls back to the uppercase one, and an implicit TLS connection is configured through smtps_proxy rather than smtp_proxy. Co-Authored-By: Claude (Opus 5) <noreply@anthropic.com> --------- Co-authored-by: Claude (Opus 5) <noreply@anthropic.com>
This commit is contained in:
@@ -16,8 +16,8 @@ Some features:
|
||||
- name: Send mail
|
||||
uses: dawidd6/action-send-mail@<REF>
|
||||
env:
|
||||
# Optional http proxy:
|
||||
HTTP_PROXY: http://proxy.example.test:3128
|
||||
# Optional proxy, NO_PROXY is honored too:
|
||||
SMTP_PROXY: http://proxy.example.test:3128
|
||||
with:
|
||||
# Specify connection via URL (replaces server_address, server_port, secure,
|
||||
# username and password)
|
||||
|
||||
@@ -6,6 +6,22 @@ import fs from "node:fs";
|
||||
import showdown from "showdown";
|
||||
import path from "node:path";
|
||||
|
||||
// smtp_proxy or smtps_proxy, exempted by no_proxy, each preferred lowercase like curl.
|
||||
function getProxy(host) {
|
||||
const env = (name) => process.env[name] || process.env[name.toUpperCase()];
|
||||
|
||||
const proxy = env("smtp_proxy") || env("smtps_proxy");
|
||||
if (!proxy) return undefined;
|
||||
|
||||
host = `.${host.toLowerCase()}`;
|
||||
const excluded = (env("no_proxy") || "")
|
||||
.split(",")
|
||||
.map((entry) => entry.trim().replace(/^\./, "").toLowerCase())
|
||||
.some((entry) => entry && (entry === "*" || host.endsWith(`.${entry}`)));
|
||||
|
||||
return excluded ? undefined : proxy;
|
||||
}
|
||||
|
||||
function getText(textOrFile, convertMarkdown) {
|
||||
let text = textOrFile;
|
||||
|
||||
@@ -188,7 +204,7 @@ async function main() {
|
||||
: undefined,
|
||||
logger: nodemailerdebug == "true" ? true : nodemailerlog,
|
||||
debug: nodemailerdebug,
|
||||
proxy: process.env.HTTP_PROXY,
|
||||
proxy: getProxy(serverAddress),
|
||||
});
|
||||
|
||||
const messageOptions = {
|
||||
|
||||
Reference in New Issue
Block a user