Fix for issue #196 (#197)

This commit is contained in:
Kroese 2024-02-14 12:26:05 +01:00 committed by GitHub
parent eaa39a13cd
commit 2afa768d34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

31
main.js
View File

@ -37,6 +37,12 @@ async function getAttachments(attachments) {
return files.map(f => ({ filename: path.basename(f), path: f, cid: f.replace(/^.*[\\\/]/, '')})) return files.map(f => ({ filename: path.basename(f), path: f, cid: f.replace(/^.*[\\\/]/, '')}))
} }
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function main() { async function main() {
try { try {
let serverAddress = core.getInput("server_address") let serverAddress = core.getInput("server_address")
@ -118,6 +124,9 @@ async function main() {
debug: nodemailerdebug, debug: nodemailerdebug,
}) })
var i = 1;
while (true) {
try {
const info = await transport.sendMail({ const info = await transport.sendMail({
from: getFrom(from, username), from: getFrom(from, username),
to: to, to: to,
@ -131,7 +140,27 @@ async function main() {
html: htmlBody ? getText(htmlBody, convertMarkdown) : undefined, html: htmlBody ? getText(htmlBody, convertMarkdown) : undefined,
priority: priority ? priority : undefined, priority: priority ? priority : undefined,
attachments: attachments ? (await getAttachments(attachments)) : undefined, attachments: attachments ? (await getAttachments(attachments)) : undefined,
}) });
break;
} catch (error) {
if (!error.message.includes("Try again later,")) {
core.setFailed(error.message)
break;
}
if (i > 10) {
core.setFailed(error.message)
break;
}
console.log("Received: " + error.message);
if (i < 2) {
console.log("Trying again in a minute...");
} else {
console.log("Trying again in " + i + " minutes...");
}
await sleep(i * 60000);
i++;
}
}
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
} }