diff --git a/action.yml b/action.yml index fe608aee9..e6b1d8860 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Send email +name: Send email with OAuth2 description: Send an email to multiple recipients author: cougargrades branding: @@ -59,6 +59,19 @@ inputs: priority: description: Set Priority level for the mail message to 'high', 'normal' (default) or 'low' required: false + # https://nodemailer.com/smtp/oauth2/ + oauth_user: + description: User email address (required) + required: false + oauth_client_id: + description: Is the registered client id of the application + required: false + oauth_client_secret: + description: Is the registered client secret of the application + required: false + oauth_refresh_token: + description: Is an optional refresh token. If it is provided then Nodemailer tries to generate a new access token if existing one expires or fails + required: false runs: using: node12 main: main.js diff --git a/main.js b/main.js index 14c932c33..17395246a 100644 --- a/main.js +++ b/main.js @@ -56,17 +56,32 @@ async function main() { const convertMarkdown = core.getInput("convert_markdown", { required: false }) const ignoreCert = core.getInput("ignore_cert", { required: false }) const priority = core.getInput("priority", { required: false }) + // --- + const oauth_user = core.getInput("oauth_user") + const oauth_client_id = core.getInput("oauth_client_id") + const oauth_client_secret = core.getInput("oauth_client_secret") + const oauth_refresh_token = core.getInput("oauth_refresh_token") 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.") } + if (!(oauth_user && oauth_client_id && oauth_client_secret && oauth_refresh_token)) { + core.warning("Some OAuth2 arguments were missing.") + } + const transport = nodemailer.createTransport({ host: serverAddress, auth: username && password ? { user: username, pass: password - } : undefined, + } : (oauth_user && oauth_client_id && oauth_client_secret && oauth_refresh_token ? { + type: 'OAuth2', + user: oauth_user, + clientId: oauth_client_id, + clientSecret: oauth_client_secret, + refreshToken: oauth_refresh_token, + } : undefined), port: serverPort, secure: secure == "true" ? true : serverPort == "465", tls: ignoreCert == "true" ? {