send-mail/main.js

50 lines
1.6 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://")) {
2020-03-01 18:37:11 +07:00
const file = body.replace("file://", "")
return fs.readFileSync(file, "utf8")
2020-03-01 05:01:03 +07:00
}
return body
}
async function main() {
2020-03-01 05:13:30 +07:00
try {
2020-03-01 18:37:11 +07:00
const server_address = core.getInput("server_address", { required: true })
const server_port = core.getInput("server_port", { required: true })
const username = core.getInput("username", { required: true })
const password = core.getInput("password", { required: true })
const subject = core.getInput("subject", { required: true })
const body = core.getInput("body", { required: true })
const to = core.getInput("to", { required: true })
const from = core.getInput("from", { required: true })
const content_type = core.getInput("content_type", { required: true })
2020-03-01 05:01:03 +07:00
2020-03-24 20:03:35 +07:00
const transport = nodemailer.createTransport({
host: server_address,
port: server_port,
secure: server_port == "465",
auth: {
user: username,
pass: password,
2020-03-01 05:13:30 +07:00
}
2020-03-24 20:03:35 +07:00
})
2020-03-01 05:01:03 +07:00
2020-03-01 18:37:11 +07:00
const info = await transport.sendMail({
2020-03-01 05:13:30 +07:00
from: `"${from}" <${username}>`,
to: to,
subject: subject,
text: content_type != "text/html" ? get_body(body) : undefined,
html: content_type == "text/html" ? get_body(body) : undefined,
2020-03-01 05:13:30 +07:00
})
2020-03-01 05:01:03 +07:00
console.log(info)
2020-03-01 05:13:30 +07:00
} catch (error) {
core.setFailed(error.message)
}
2020-03-01 05:01:03 +07:00
}
main()