2013-03-14 16 views
18

Sto cercando di eseguire sendmailR su Windows con il seguente codice:Usa sendmailR con Windows

## Not run: 
from <- "<[email protected]>" # sprintf("<[email protected]\\%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.")) 

E ottenere il seguente errore:

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 dare una soluzione per Linux, e ho sarebbe grato per un consiglio per gli utenti di Windows.

Grazie.

+5

Questo non risponde alla tua domanda ma in alternativa puoi usare il mio GitHub [gmailR] (https://github.com/trinker/gmailR) che so funziona con Windows ed è per gmail. È qualcosa che ho inscatolato come pacchetto per uso personale, ma non è il mio lavoro. –

+2

Nice Tyler - grazie. :) p.s: Sarei ancora interessato a capire questo problema di sendmailR ... –

risposta

5

Si potrebbe dare il nuovo pacchetto mailR un colpo: http://cran.r-project.org/web/packages/mailR/index.html

Il seguente la chiamata dovrebbe quindi funzionare:

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) 
+0

Ho ancora un errore. Stavo ottenendo lo stesso errore dell'OP e ora quando ho provato questo ho 'Controlla documentazione per includere tutti i parametri obbligatori per stabilire una connessione SMTP. ... Sì. Diceva che stabilire non stabilire ... – NealC

4

Ho usato per inviare e-mail tramite R utilizzando queste linee.

Supponiamo che il vostro e-mail è [email protected] utilizzando la finestra del sistema operativo (il mio sistema operativo)

library(sendmailR) 

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

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

Ciao Hianni. In entrambi i casi viene visualizzato: Errore in wait_for (250): Errore SMTP: 5.7.1 [37.142.250.150] L'IP che si sta utilizzando per inviare la posta non è autorizzato a –

+1

Ehi @TalGalili è strano Ho provato e non l'ho fatto t ottenere qualsiasi messaggio di errore, mi dispiace. –

+1

o.k., grazie Gianni. –

0

Come alternativa all'utilizzo di sendmailR si potrebbe provare questo:

Analizzare insieme un VB-Script (si veda ad esempio http://www.paulsadowski.com/wsh/cdo.htm) e poi chiamalo tramite shell.

Questo potrebbe essere simile a questo:

SendMail <- function(from="[email protected]",to="[email protected]",text="Hallo",subject="Sag Hallo",smtp="smtp.my.server.de",user="me.myself.and.i",pw="123"){ 
require(stringr) 
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=""), 
sep="\n") 

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

objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/sendusing\") = 2 

'Name or IP of Remote SMTP Server 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/smtpserver\") = ",'"',smtp,'"'," 

'Type of authentication, NONE, Basic (Base64 encoded), NTLM 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate\") = cdoBasic 

'Your UserID on the SMTP server 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/sendusername\") = ",'"',user,'"'," 

'Your password on the SMTP server 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/sendpassword\") = ",'"',pw,'"', " 

'Server port (typically 25) 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/smtpserverport\") = 25 

'Use SSL for the connection (False or True) 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/smtpusessl\") = False 

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) 
objMessage.Configuration.Fields.Item _ 
(\"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout\") = 60 
objMessage.Configuration.Fields.Update 

'==End remote SMTP server configuration section== 

objMessage.Send 
",sep="") 

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

... e usarlo in questo modo:

SendMail(
    from="[email protected]", 
    to="[email protected]", 
    text="Hallo", 
    subject="readThis", 
    smtp="smtp.andI.com", 
    user="[email protected]", 
    pw="123456" 
    )