Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
au5ton committed Jan 27, 2022
1 parent bbe8abd commit de0fc17
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Send email
name: Send email with OAuth2
description: Send an email to multiple recipients
author: cougargrades
branding:
Expand Down Expand Up @@ -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
17 changes: 16 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ? {
Expand Down

0 comments on commit de0fc17

Please sign in to comment.