rpremraj / mailR

A utility to send emails from the R programming environment
http://rpremraj.github.io/mailR/
190 stars 57 forks source link

Unable to send email from R (Error in ls(envir = envir, all.names = private)) #25

Closed jinmook928 closed 8 years ago

jinmook928 commented 9 years ago

Hi,

I am trying to test sending an email from R with mailR package, but I keep getting such error message which I do not understand. I browsed around if there's any existing solution, but failed to find one.

I also tested running the same smtp host with port =25 thru telnet and connection to smtp server looks fine via telnet. So, port and smtp host doesn't seem to be an issue. It only becomes an issue when I run thru R for some reason. Can someone help interpreting the error here? Greatly appreciate.

Command: send.mail(from = "abc@company.com", to = "xyz@company.com", subject = "Hello this is a testing message", body = "And this is a body text", smtp = list(host.name = "mailhub.company.com",port=25), authenticate = FALSE, send = TRUE,debug=TRUE)

Error:

DEBUG: JavaMail version 1.5.2 DEBUG: successfully loaded resource: /META-INF/javamail.default.providers DEBUG: Tables of loaded providers DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]} DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]} DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle] DEBUG SMTP: useEhlo true, useAuth false DEBUG SMTP: trying to connect to host "mailhub.company.com", port 25, isSSL false Error in ls(envir = envir, all.names = private) : invalid 'envir' argument

rpremraj commented 9 years ago

Have you checked whether you need to configure R to connect via a proxy?

nathaneastwood commented 9 years ago

I'm having the same issue. @rpremraj can you please enlighten me more on your solution? FYI, I am running the following code:

sender <- "<blah@plymouth.ac.uk>"  # Replace with a valid address
recipients <- c("<blahblah@plymouth.ac.uk>")  
email <- send.mail(from = sender,
                   to = recipients,
                   subject = "Subject of the email",
                   body = "Body of the email",
                   smtp = list(host.name = "casarray.uopnet.plymouth.ac.uk",
                               user.name = "xxxxx",
                               passwd = "xxxxxxx",
                               ssl = TRUE),
                   authenticate = TRUE,
                   debug = TRUE)

The debug information is:

DEBUG: JavaMail version 1.5.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "casarray.uopnet.plymouth.ac.uk", port 465, isSSL false
Error in ls(envir = envir, all.names = private) : 
  invalid 'envir' argument

I've looked through all of the closed threads for this issue and can't see anything that helps. I am trying to send these emails through a Microsoft Exchange server.

jinmook928 commented 9 years ago

@rpremraj Thanks for your time to look into this. For Proxy configuration, can you elaborate a bit more such as where and how to check/set it up? I've checked stackoverflow and other closed issues as well but I am having trouble finding a guidance to address the problem.

Also further debugging, I found following message as well:

If you look at line 11, the code seems to be failing while sending the email to the server via apache.common.mail..

8: .jrcall(x, name, ...) 9: .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, .jcast(if (inherits(o, "jobjRef") || inherits(o, "jarrayRef")) o else cl, "java/lang/Object"), .jnew("java/lang/String", method), j_p, j_pc, use.true.class = TRUE, evalString = simplify, evalArray = FALSE) 10: .jcheck(silent = FALSE) 11: stop(list(message = "org.apache.commons.mail.EmailException: Sending the email to the following server failed : mailhub.company.com:25", call = .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, .jcast(if (inherits(o, "jobjRef") || inherits(o, "jarrayRef")) o else cl, "java/lang/ 12: conditionMessage(cond) 13: conditionMessage.condition(cond) 14: c$message 15: $.Throwable(c, "message")

atleypnorth commented 9 years ago

I am seeing exactly the same issue. From the same PC I can telnet to the mailhub on port 25 and get the prompt, so does not appear to be a proxy issue

Also see the same problem whether I run R with --internet2 or not

rpremraj commented 9 years ago

Sorry --- rather hard for me to dig deeper into since I cannot reproduce this error both on Mac and Windows. I will continue looking...

fmparzen commented 9 years ago

Has anyone figured this out? I am getting the exact same error using essentially the example code for sending through smtp.gmail.com

Error in ls(envir = envir, all.names = private) : invalid 'envir' argument

rpremraj commented 9 years ago

Just for the sake of confirming whether the problem indeed lies within mailR or this is a network related issue, could gmail users test sending emails using the gmailr package?

@jennybc has shared detailed instructions on how to use the package (https://github.com/jennybc/send-email-with-r).

Would be great if you could share your experiences in this thread to help resolve the issue.

atleypnorth commented 9 years ago

I could send emails via Python using the same SMTP server / username etc so it does seem to be something with R or the implementation in R

rpremraj commented 9 years ago

@atleypnorth so no luck with gmailr either?

TomBomb4dil commented 9 years ago

Hi, I had the same issue excepted that the error occured before the debug output (even with debug = TRUE). It was weird because the mail sending was ok the morning but didn't worked 2 hours later... Finally I found my mistake:

Good luck

rpremraj commented 9 years ago

Thanks @TomBomb4dil.

Multiple recipients indeed need to be passed to send.mail() as a character vector. This applies to the CC and BCC fields as well.

MohMaz commented 9 years ago

I get this error too. I'm Using Windows 8 X84, R 3.2.2 and JDK 1.8

krose commented 8 years ago

@NattyE Did you find a solution? I get the same error as you do.

nathaneastwood commented 8 years ago

No I didn't. Though I suspect it may have something to do with my work's firewall/VPN, but I cannot be certain.

rpremraj commented 8 years ago

Folks, I strongly feel this is a connectivity issue. Unfortunately I can't reproduce the error at my end either from work or from home.

ablazko commented 8 years ago

@rpremraj Maybe I can point you a way so you can reproduce this error and try to find a solution. I was using send.mail() function with no problem at all, and then I start getting the same message error:

Error in ls(envir = envir, all.names = private) : invalid 'envir' argument

Scenario 1: works perfectly! smtp = list(host.name="smtp.gmail.com", port=465, user.name="andre.blazko@gmail.com", passwd="mypassword", ssl=TRUE)

Scenario 2: Error! smtp = list(host.name="smtp.gmail.com", port=465, user.name="andre.blazko@domain.com", passwd="mypassword", ssl=TRUE)

The thing is that the error seems to be related with the @domain. I bought this new domain, configured an Google Business account for it and Gmail/Calendar/etc is working just fine. But the send.mail() stopped working. All other parameters in the function are equals. Only @gmail and @domain is different in the two scenarios.

Hope this can help! Regards, Blazko

ablazko commented 8 years ago

@rpremraj I get in touch with Google support and I accomplish to solve this issue following the steps above.

  1. Login in to your email account in Gmail
  2. Click 'Manage this domain' located in the drop menu available in the upper right corner
  3. You'll be now in 'Admin console'
  4. Click 'Security'
  5. Click 'Basic settings'
  6. In 'Less secure apps', click 'Go to settings for less secure apps'
  7. Select the option 'Enforce access to less secure apps for all users' and then click on 'Save'

Voilà!!!!

Now send.mail() is working perfectly! :) In Google Business accounts, you must change this option manually. In public accounts of Gmail, this option (item 7) is the default behavior.

https://support.google.com/a/answer/6260879?hl=en

nathaneastwood commented 8 years ago

@ablazko this sounds like a good solution. Do you know of any similar settings in Microsoft Exchange (Outlook)?

ablazko commented 8 years ago

Hi Nathan, unfortunately I'm not. But I would bet that there is a similar solution on it. Maybe the IT guys might have a clue knowing how this issue was fixed in Google Business. I don't have this expertise.

Wish you luck.

Regards, Blazko

Abs, Blazko

2015-11-30 7:41 GMT-02:00 Nathan Eastwood notifications@github.com:

@ablazko https://github.com/ablazko this sounds like a good solution. Do you know of any similar settings in Microsoft Exchange (Outlook).

— Reply to this email directly or view it on GitHub https://github.com/rpremraj/mailR/issues/25#issuecomment-160575425.

krose commented 8 years ago

@NattyE I have asked my IT department again in light of the new info. It has already been at their table, but it's worth a shot.

rpremraj commented 8 years ago

Try installing the latest version of mailR from GitHub. I am curious to see whether the changes will result in a more descriptive error message. Thx!

nathaneastwood commented 8 years ago

@rpremraj I have updated to the latest version, I also ran this by our IT department and they asked me to try with a different host name. I now get the following error

invalid 'envir' argument[1] "Java-Object{org.apache.commons.mail.SimpleEmail@28d25987}"

Any ideas? This is the same if I have debug set to TRUE or FALSE.

rpremraj commented 8 years ago

@NattyE The new error message is a result of a minor update to my code to catch error messages from Java. I was hoping it to be more descriptive than that. But essentially you have the same issue as before with this hostname as well. sigh

Just for the sake of testing, have you tried mailR with a private mail server such a gmail? I feel convinced that something is blocking your connection to the SMTP server... this could be a windows service running in the background, virus scanners, firewalls, or the like.

Let's agree to use this thread to share any updates from our side.

nathaneastwood commented 8 years ago

@rpremraj I finally got it to work with the help of IT support. It was simply finding the correct smtp configurations (our place of work has a lot!). Thanks for spending time looking into this and sorry if it has been sending you on a wild goose chase. I would thoroughly recommend that anyone who is struggling with it should contact their IT department and double check their smtp configs. It took my IT support a while to work out which ones I needed!

EDIT: Your IT may also have restrictions, for example I cannot send mail using an external mail server. I can send to an external mail server, but not from one.

babelfishy commented 8 years ago

I want to report how I managed to fix this problem in my case.

SMTP settings - according to my IT help desk - were supposed to be:

smtp.xxx.edu Port: 587 Encryption: TLS

After looking here https://www.fastmail.com/help/technical/ssltlsstarttls.html, through trial an error (e.g. port 465 didn't work), I found that by changing the port to port 25, it suddenly worked.

No idea why. Maybe this will help others.

rpremraj commented 8 years ago

No activity on this thread... presuming issue resolved.

kvswetha commented 8 years ago

Hi Premraj,

I am getting exactly same error mentioned in this thread. I went through all the solutions available on stack overflow. I am able use your package on public gmail.com account. But this doesnt work on my corporate gmail account. IT is not ready to enable "less secure apps". Do you have any solution to this??

ResourceX commented 7 years ago

Hey I got this to work using mailR. It's all in the settings of the account you are trying to use.

This was helpful: https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server

Some key points

  1. The IMAP settings - update these to "enable" like the link says
  2. The user.name needs to be the full email. For my personnel account, I could leave off the gmail domain.
  3. Like noted in the link, you are using gmails smtp, that's the host.name, for a while I was confused and tried to use my domain here.
library(mailR)

send.mail(from = "helpdesk@yourdomain.net",
          to = "yourname@gmail.com",
          subject = "email mail from the helpdesk",
          body = "test",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "helpdesk@yourdomain.net",    passwd = "helpdesk_password", ssl = TRUE),
          authenticate = T,
          send = TRUE)
rynesherman commented 6 years ago

I realize this is an old thread and the problem I am experiencing may not be the same, but this appears to be the most similar to my current problem. I have used send.mail() many times before (though it has been about a year since I last used it). Here is the error message I am receiving:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410) at org.apache.commons.mail.Email.send(Email.java:1437) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at RJavaTools.invokeMethod(RJavaTools.java:386) Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout 60000; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697) at javax.mail.Service.connect(Service.java:386) at javax.mail.Service.connect(Service.java:245) at javax.mail.Service.connect(Service.java:194) at javax.mail.Transport.send0(Transport.java:253) at javax.mail.Transport.send(Transport.java:124) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400) ... 6 more Caused by: java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.security.ssl.SSLSocketImpl.connect(Unknown Source) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019) ... 13 more NULL Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465

The code I am running is the same as ResourceX above, though I am also including an attachment (which is also something I've done many times before with no trouble). For clarity, I am pasting my code anyway:

send.mail(from = "username@gmail.com", to = "address", subject = "subject of email", body = "body of email", html = TRUE, smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "username@gmail.com", passwd = pass, ssl=TRUE), attach.files = "Filename.pdf"), authenticate = TRUE, send = TRUE )

mcoirad-gmmb commented 6 years ago

@rynesherman I had the same error. Its a firewall/server issue. In my case I had a shiny app running on a AWS EC2 instance that did not have the 587 port open. Since you are using 465, I would check with your IT or just scan the ports of whatever server you are using to see that they are open.

In my case there was nothing I could do as I did not have access to the server to open the ports. Your results may vary.

johnsnow09 commented 3 years ago

I am getting this error when trying to send mail through mailR on Rstudio. But when I use python with same port 465 on same mail ids it works perfectly. And its my personal pc so there is no as such corporate firewall at play and also python is able to send it thro'.

Here is the error:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410) at org.apache.commons.mail.Email.send(Email.java:1437) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at RJavaTools.invokeMethod(RJavaTools.java:386) Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465; nested exception is: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2055) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697) at javax.mail.Service.connect(Service.java:386) at javax.mail.Service.connect(Service.java:245) at javax.mail.Service.connect(Service.java:194) at javax.mail.Transport.send0(Transport.java:253) at javax.mail.Transport.send(Transport.java:124) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400) ... 6 more Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) at sun.security.ssl.HandshakeContext.<init>(Unknown Source) at sun.security.ssl.ClientHandshakeContext.<init>(Unknown Source) at sun.security.ssl.TransportContext.kickstart(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:348) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019) ... 13 more Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465