issue using sendemailR [duplicate]
Asked Answered
J

1

2

I am trying to use sendemailR package in R but I am getting an error I don't know how to fix.

When trying the default parameters:

library(sendmailR)
from <- "your_email"
to <- "your_email"
subject <- "Test send email in R"
body <- "It works!"                     
mailControl=list(smtpServer="smtp.gmail.com")
sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)

I get the 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) :
Gmail SMTP Server:25 cannot be opened

So I change the port to 465 and it seems to work

library(sendmailR)
from <- "your_email"
to <- "your_email"
subject <- "Test send email in R"
body <- "It works!"                     
mailControl=list(smtpServer="smtp.gmail.com", smtpPort="465")
sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)

but then I get the following error

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

Any idea what's happening?

This is the version of R and Windows

R version 3.0.3 (2014-03-06) -- "Warm Puppy"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

Thanks!

Jezebel answered 21/5, 2014 at 19:28 Comment(2)
smtp.gmail.com requires authentication, which is not supported by sendmailRLightface
I also think that to should contain a valid email addressSelenium
L
4

There are two things that need attention in your example:

As @David Arenburg commented, to should contain a valid email address.

The second thing is the smtp server you are using: smtp.gmail.com. This server need authentication which is not supported by sendmailR.

You can use an smtp server that does not require authentication (e.g. the restricted gmail smtp server: aspmx.l.google.com, port 25, see here for details)

The other option is to use the mailR package that allows authentication.

Try something like (of course you have to put valid email addresses and user.name and passwd to work):

library(mailR)
sender <- "[email protected]"
recipients <- c("[email protected]")
send.mail(from = sender,
to = recipients,
subject="Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465, 
        user.name="[email protected]", passwd="YOURPASSWORD", ssl=TRUE),
authenticate = TRUE,
send = TRUE)

Hope it helps,

alex

Lightface answered 21/5, 2014 at 21:37 Comment(1)
Thanks, mailR works perfect for me. I actually wanted to send attachments on the mail and I can do it with this package.Jezebel

© 2022 - 2024 — McMap. All rights reserved.