I think I have the exact same problem as this question. I mean literally, it might be the exact same. But it seems like that never got an answer so I'll post mine.
I'm trying to get R to send an email. (Ultimately it'll be part of trycatch and will email me when R errors, but babysteps).
The code is running from my work computer which is behind all sorts of firewall/microsoft protection/vpn that might be causing issues.
I've successfully got it to work using this code (notable because it means it CAN send emails):
library(Microsoft365R)
my_outlook <- get_personal_outlook()
my_email <- my_outlook$create_email(content_type = "html")$
set_body("<p>Testing to see if R can email</strong>.</p>")$
set_subject("Did R email you?")$
set_recipients(to = c("Person@mywork.org", "Person2@mywork.org"))$
send()
The problem is that this pops open a chrome window that asks me to login elsewhere. I'm hoping to get this R code running on a virtual machine that wont be actively watched. I.e. a script will run the R code daily at 1pm, and nobody will be there to watch it and click around in a browser window if it needs to log in.
So instead of a Microsoft365R solution, I'm trying to use this:
library(mailR)
sender<-"MyPersonal@hotmail.com"
recipients<-c("Mywork@myWork.org")
email<-send.mail(from=sender, to=recipients, subject="Test Email", body="Testing to see if R can email", smtp = list(host.name = "smtp.live.com", port = 587,user.name = "MyPersonal@hotmail", passwd = "MyPassword", tls = TRUE), authenticate=FALSE, send=TRUE)
But I get this error:
EmailException (Java): Sending the email to the following server failed : smtp.live.com:587
I've also tried my gmail instead of my hotmail:
send.mail(from = "mypersonal@gmail.com",
to = "mypersonal@gmail.com",
subject = "test",
body = "test",
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "myUsername", passwd = "MyPassword", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
And I get this error:
EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465[1] "Java-Object{org.apache.commons.mail.SimpleEmail@496bc455}"
Any ideas? The errors are so vague I'm not sure what to change.