Use sendmailR with Windows

Tal Galili picture Tal Galili · Mar 14, 2013 · Viewed 16.1k times · Source

I'm trying to run sendmailR on Windows with the following code:

## Not run: 
from <- "<[email protected]>" # sprintf("<sendmailR@\\%s>", Sys.info()[4])
to <- "<[email protected]>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
         control=list(smtpServer="ASPMX.L.GOOGLE.COM."))

And get the following error:

Error in socketConnection(host = server, port = port, blocking = TRUE) : 
  cannot open the connection
In addition: Warning message:
In socketConnection(host = server, port = port, blocking = TRUE) :
  smtp.gmail.com [email protected]:statisfun:25 cannot be opened

The answer here give a solution for Linux, and I would be grateful for advice for Windows users.

Thanks.

Answer

Rahul Premraj picture Rahul Premraj · Mar 11, 2014

You could give the new mailR package a shot: http://cran.r-project.org/web/packages/mailR/index.html

The following call should then work:

send.mail(from = "[email protected]",
          to = "[email protected]",
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "tal.galili", passwd = "PASSWORD", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)