I want to send a customised email from R when running Gitlab CI. My R code works on my computer. However, the same R code run in a Gitlab pipeline failed with the following error:
Sending email to smtp://smtp.office365.com:587 .
Error in curl_fetch_memory(url, handle = h) : Login denied
Calls: smtp -> curl_fetch_memory
Execution halted
ERROR: Job failed: exit code 1
The same error message occurs using two different R packages, i.e. {emayili} and {blastula}. My guess is that the solution (if a solution exists?) lies in the parameters of the SMTP server of Gitlab... but as a R user this goes beyond my expertise. So my question is:
Does someone know some "magic" to send customised email from R when running a Gitlab CI pipeline?
Here is the code I used for an Outlook account:
My .gitlab-ci.yml file:
image: rocker/tidyverse
test:
script:
- Rscript send_message.R
My send_message.R file with the R package {emayili}:
remotes::install_github("datawookie/emayili")
install.packages("magrittr")
library(emayili)
library(magrittr)
email <- envelope()
email <- email %>%
from("r_user@outlook.com") %>%
to("john_doe@example.com") %>%
subject("This is a plain text message!") %>%
text("Hello! This is a test.")
smtp <- server(host = "smtp.office365.com",
port = 587,
username = "r_user@outlook.com",
password = "**********")
smtp(email)
Or the send_message.R file using the R package {blastula}:
install.packages("blastula")
library(blastula)
## Run manually once to get the outlook_creds file
#create_smtp_creds_file(
#file = "outlook_creds",
#user = "r_user@outlook.com",
#host = "smtp.office365.com",
#port = 587,
#use_ssl = TRUE
#)
test_message <- prepare_test_message()
test_message %>%
smtp_send(
from = "r_user@outlook.com",
to = "john_doe@outlook.com",
subject = "Testing the `smtp_send()` function",
credentials = creds_file(file = "outlook_creds")
)