send-mail/main.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-01 05:01:03 +07:00
const nodemailer = require("nodemailer")
const core = require("@actions/core")
const fs = require("fs")
function get_body(body) {
if (body.startsWith("file://")) {
body = body.replace("file://", "")
body = fs.readFileSync(body, "utf8")
2020-03-01 05:01:03 +07:00
}
return body
}
async function main() {
2020-03-01 05:13:30 +07:00
try {
server_address = core.getInput("server_address", { required: true })
server_port = core.getInput("server_port", { required: true })
username = core.getInput("username", { required: true })
password = core.getInput("password", { required: true })
subject = core.getInput("subject", { required: true })
body = core.getInput("body", { required: true })
to = core.getInput("to", { required: true })
from = core.getInput("from", { required: true })
html = core.getInput("html") || "false"
2020-03-01 05:01:03 +07:00
2020-03-01 05:13:30 +07:00
transport = nodemailer.createTransport({
host: server_address,
port: server_port,
secure: server_port == "465",
auth: {
user: username,
pass: password,
}
})
2020-03-01 05:01:03 +07:00
2020-03-01 05:13:30 +07:00
info = await transport.sendMail({
from: `"${from}" <${username}>`,
to: to,
subject: subject,
text: html == "false" ? get_body(body) : undefined,
html: html == "true" ? get_body(body) : undefined,
})
2020-03-01 05:01:03 +07:00
core.info(info)
2020-03-01 05:13:30 +07:00
} catch (error) {
core.setFailed(error.message)
}
2020-03-01 05:01:03 +07:00
}
main()