0

I coded an R script in order to create mail alert every day at a predetermined time. When I manually execute the code, it works great and I can receive the email in no time. However, when I run the script with task scheduler, it just failed to get the task done.

Below is my code, and my question is did I make a mistake when assigning the task or writing the code?

library(mailR)

message1="hello"
message2="hello"

 send.mail(from ="xxxxxx@gmail.com",
      to = c("xxxxxx@gmail.com"),
      subject = "Summary of stock performance",
      #body =paste(message1,"\r\n",message2),
      body = paste("<p> Overall </p>",message1,"<p>",message2,"<p>"),
      #body = paste(message1,"\r\n",message2,"\r\n"),
      #body="hello",
      html = TRUE,
      inline = TRUE,
      smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "xxxxxx", passwd = "xxxxxxx", ssl = TRUE),
      authenticate = TRUE,
      send = TRUE)
Kay
  • 33
  • 4
  • 1
    You should remove your email address. – tmsdajpa Jul 18 '19 at 14:48
  • does it fail with any errors? or just not send anything? – morgan121 Jul 18 '19 at 14:48
  • @tmsdajpa Sorry my bad. I will fix it – Kay Jul 18 '19 at 14:52
  • @RAB When I run it no matter in rstudio or in command prompt, it ends up with no error. But it sends me an email only when I manually run it in rstudio – Kay Jul 18 '19 at 14:54
  • Are you actually using the task scheduler like this : https://stackoverflow.com/a/21548386/10447055 ? – Gainz Jul 18 '19 at 15:41
  • @Gainz In action part of task scheduler, I entered "C:\Program Files\R\R-3.6.0\bin\Rscript.exe" in program/script line , and typed "C:\r project 1\mail_R_testing.R" in argument box. The difference compared with your version is the direction of the dashes. – Kay Jul 18 '19 at 15:55
  • 2
    Did you try adding another function to your testing script to make sure the task scheduler is working correctly? E.g., send your e-mail and save a txt file. – David Klotz Jul 18 '19 at 17:34
  • That is a great idea. If I can see a text file, that means the script is run successfully. – Kay Jul 18 '19 at 23:31

0 Answers0