Use sendmailR with Windows

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

## Not run: 
from <- "<>" # sprintf("<sendmailR@\\%s>",[4])
to <- "<>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,

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) : cannot be opened

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



You could give the new mailR package a shot:

The following call should then work:

send.mail(from = "",
          to = "",
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list( = "", port = 465, = "tal.galili", passwd = "PASSWORD", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

I used to send emails via R using these lines.

Suppose your email is using window OS (my operation system)


# 1 case
from <- sprintf("<sendmailR@%s>",[4]) 
to <- "<>" 
subject <- "Hello from R" 
msg <- "my first email" 
sendmail(from, to, subject, msg,control=list(smtpServer="ASPMX.L.GOOGLE.COM")) 

# 2 case
from <- sprintf("<>",[4]) 
to <- "<>" 
subject <- "Hello from R" 
msg <- "my first email" 
sendmail(from, to, subject, msg,control=list(smtpServer="ASPMX.L.GOOGLE.COM")) 

Any time that sendmailR fails to authenticate, one gets the not so helpful message that

Error in if (code == lcode) { : argument is of length zero

This can be for many reasons, including server side reasons. In my case, I needed to put my IP on the server's whitelist. @alko989 declares at issue using sendemailR that authentication ... is not supported by sendmailR, and as of the 2015-Feb-20 publishing of sendmailR, the only control parameters are smtpServer, smtpPort & verbose, so nothing for user, password, ssl, tls, etc. Mail servers today tend to be much more secure than the mail servers of the past, so that's a serious limitation of sendmailR.

As an alternative to using sendmailR you might try this:

Parse together a VB-Script (see e.g. ) and then call it via shell.

This might look like this:

SendMail <- function(from="",to="",text="Hallo",subject="Sag Hallo",smtp="",user="me.myself.and.i",pw="123"){
part1 <- "Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication 
Const cdoNTLM = 2 'NTLM "

part2 <- paste(paste("Set objMessage = CreateObject(",'"',"CDO.Message",'"',")" ,sep=""),
paste("objMessage.Subject = ",'"',subject,'"',sep=""),
paste("objMessage.From = ",'"',from,'"',sep=""),
paste("objMessage.To = ",'"',to,'"',sep=""),
paste("objMessage.TextBody = ",'"',text,'"',sep=""),

part3 <- paste(
"'==This section provides the configuration information for the remote SMTP server. 

objMessage.Configuration.Fields.Item _ 
(\"\") = 2

'Name or IP of Remote SMTP Server 
objMessage.Configuration.Fields.Item _ 
(\"\") = ",'"',smtp,'"'," 

'Type of authentication, NONE, Basic (Base64 encoded), NTLM 
objMessage.Configuration.Fields.Item _ 
(\"\") = cdoBasic 

'Your UserID on the SMTP server 
objMessage.Configuration.Fields.Item _ 
(\"\") = ",'"',user,'"'," 

'Your password on the SMTP server 
objMessage.Configuration.Fields.Item _ 
(\"\") = ",'"',pw,'"', "

'Server port (typically 25) 
objMessage.Configuration.Fields.Item _ 
(\"\") = 25 

'Use SSL for the connection (False or True) 
objMessage.Configuration.Fields.Item _ 
(\"\") = False 

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) 
objMessage.Configuration.Fields.Item _ 
(\"\") = 60 

'==End remote SMTP server configuration section== 


vbsscript <- paste(part1,part2,part3,sep="\n\n\n")
writeLines(vbsscript, "sendmail.vbs")

... and use it like this:


Need Your Help

Convert an Array of integers to a String

android arraylist hashmap android-activity

First, I'm completely new to Java programming (just started 3 weeks ago), and I tried my best for two days to solve it. but with no success.

How do I find the "Preferences" menu in Eclipse in OS X?

eclipse macos preferences

In installing PyDev in eclipse, I need to go to window &gt; preferences &gt; pydev . . .