blastula icon indicating copy to clipboard operation
blastula copied to clipboard

SMTP error 214 when sending from Github Actions

Open collinschwantes opened this issue 3 years ago • 2 comments

I'm using Github Actions to automate email distribution and as of 25 April started receiving a 214 error when sending emails from github actions. The code works locally and the system admins for my organization say they have not changed the email policy.

I've tried setting up 2-step verification and using an app password thinking that the google policy change for low security apps may have been implemented but that did not fix the issue. Again, I am able to send emails to the same recipients from my local machine using blastula and the same credentials as those supplied to github actions.

Screen Shot 2022-04-26 at 12 29 52 PM

collinschwantes avatar Apr 26 '22 17:04 collinschwantes

Here is the containerTemplateUtils function:

#' Send email alerts to updated automation reports
#'
#' @param to A vector of email addresses serving as primary recipients for the
#'   message.
#' @param from The email address of the sender.
#' @param attach Logical. Should reports be attached to email? Default is
#'   FALSE. If TRUE, all HTML reports found in *"outputs"* folder will be
#'   attached to email.
#' @param test Logical. Is this an email alert for testing automation reports?
#'   Default is FALSE. If TRUE, subject includes test and upload path will include
#'   the current git branch in the file path (e.g. https://project.secure.eha.io/refs/fix/missing_documentation/file.txt)
#' @param project_name String. Name of the project to use in email subject and body text.
#' @param path String. Name of folder or file path for attachment items
#' @param pattern String. Regex pattern to select specific files in path.
#'
#' @seealso `browseVignettes("blastula")`
#'
#' @return Invisible. Update email sent to list of recipients in `to`
#'
#' @export send_email_update

send_email_update <- function(to,
                              from = "[email protected]",
                              project_name,
                              attach = FALSE,
                              test = FALSE,
                              path = "outputs",
                              pattern= "\\.html") {
  ## Set SMTP server credentials
  email_credentials <- blastula::creds_envvar(
    user = from,
    host = "smtp.gmail.com",
    port = 587,
    use_ssl = TRUE
  )

  ## Create human readable data and time
  readable_date_time <- blastula::add_readable_time()

  ## List out reports found in "outputs" folder
  reports <- list.files(path, pattern = pattern)

  ## Create links to HTML reports and create email
  if (test) {
    report_links <- sprintf("%s/%s/outputs/%s\n",
                            Sys.getenv("URL_PREFIX"),
                            Sys.getenv("GITHUB_REF"),
                            reports)


    subject <- glue::glue(
      "Testing {project_name} Automated Reports for ", {readable_date_time}
    )

    report_links_collapse <- glue::glue_collapse(report_links,sep = ", ",last = "and ")

    email <- blastula::compose_email(
      body = glue::glue(
        "The test automation reports can be viewed here: \n\n",
        {report_links_collapse}, "\n\n",
        "A copy/copies of the {project_name} automated report/s is/are also attached. \n\n"
      ) |>
        blastula::md()
    )
  } else {
    report_links <- paste0(
      Sys.getenv("URL_PREFIX"), "/", reports, "\n"
    )

    subject <- glue::glue(
      "{project_name} Automated Reports for ", {readable_date_time}
    )

    report_links_collapse <- glue::glue_collapse(report_links,sep = ", ",last = "and ")

    email <- blastula::compose_email(
      body = glue::glue(
        "The {project_name} automated reports can be viewed here: \n\n",
        {report_links_collapse}, "\n\n",
        "A copy/copies of the {project_name} automated report/s is/are also attached. \n\n"
      ) |>
        blastula::md()
    )
  }

  ## Add attachements
  if (attach) {
    for (i in list.files(path = path, pattern = pattern, full.names = TRUE)) {
      email <- email |>
        blastula::add_attachment(file = i)
    }
  } else {
    email
  }

  ## Send email
  blastula::smtp_send(
    email = email,
    to = to,
    from = from,
    subject = subject,
    credentials = email_credentials
  )
}

collinschwantes avatar Apr 26 '22 17:04 collinschwantes

Any thoughts on this one?

lindblb avatar Feb 27 '24 19:02 lindblb