Search code examples
remailsmtpgmailsendmailr

Use sendmailR with Windows


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.


Solution

  • 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)