rpremraj / mailR

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

java.lang.NoClassDefFoundError: javax/activation/DataSource #77

Open ghost opened 6 years ago

ghost commented 6 years ago

Trying to send an email after buying a new MacBook. I have updated all my packages, installed java9 but I am getting this error. I am using this package on another macbook with exactly same settings, so why is this not working?

send.mail(from = sender, to = c("lrs.ngrd@gmail.com"), subject = subject_line, body = "/Users/larsnygaard/table_rank_eod/_html/email.html", html = TRUE, smtp = list(host.name = "smtp.webhuset.no", port = 143,user.name = "info@norquant.no",passwd = "xxxxxxx", ssl = TRUE), authenticate = TRUE, send = TRUE, debug = TRUE)

Error in .jnew("org.apache.commons.mail.HtmlEmail") : java.lang.NoClassDefFoundError: javax/activation/DataSource

msrodrigues commented 6 years ago

I have the same problem, Error in .jnew("org.apache.commons.mail.ImageHtmlEmail") : java.lang.NoClassDefFoundError: javax/activation/DataSource looked everywhere... :( I think it is a java path issue, did you discover anything?

Hellvince commented 6 years ago

Hi ! MailR was working fine on my previous laptop with Java8 installed.

I just got a brand new laptop, installed Java10, fired R/RStudio and... mailR wasn't working anymore. Same error : java.lang.NoClassDefFoundError: javax/activation/DataSource

Quick fix : I installed Java8 (on top of the current Java10), modified the JAVA_HOME system variable to target the right Java version and... voilà ! mailR is working again.

IMO, it boils down to a Java version issue, at least partially.

vfulco commented 6 years ago

Same here on Ubuntu 16.04. Forced to upgrade to 18.04 and everything, this breaks and I know nothing about Java.

rpremraj commented 6 years ago

mailR will be updated in the coming days; I hope this issue will be resolved.

@Nygdat On my Mac, I use the Java version that comes with the OS. Installing newest Java version from Oracle resulted in a mess.

msrodrigues commented 6 years ago

mailR will be updated in the coming days; I hope this issue will be resolved. This is exciting news! Will it still need java?

rpremraj commented 6 years ago

Sadly yes, because it depends on Commons Email (https://commons.apache.org/proper/commons-email/).

In future I will try to break away from this considering most issues reported here relate to Java.

shubhangisharma1742 commented 6 years ago

Hi, encountering same problem. reinstalled java 8 but still facing the same issue. Any suggestions?

NicolasNeiman commented 6 years ago

Hi, I'm having the same issue with Java 8 Any updates ?

Vancamjr commented 6 years ago

Same issue hoped to find a fix in-progress via install_github() -> nojoy [mac 10.13.4] Agree: Freedom from Java would solve majority of headaches (a major adoption barrier).

rpremraj commented 6 years ago

Freedom from Java: Agreed!

I am forced to use Java 8 at work, and the package works well... Will upgrade Java libraries as interim solution to see whether it solves current issues.

mkroening commented 6 years ago

The Java EE modules are deprecated from Java 9 onwards: http://openjdk.java.net/jeps/320 The general recommendation is providing those modules as dependencies. https://maven.apache.org/surefire/maven-surefire-plugin/java9.html To solve this particular problem it would be "javax.activation:javax.activation-api".

wx2000 commented 6 years ago

Hi, I'm having the same issue with Java 9 Any updates ?

ghost commented 6 years ago

+1 looking forward to the update...

scottyraymond commented 6 years ago

@Hellvince thank you very much for your comment. I was able to take the following steps based on your suggestion. I am using Windows 10, RStudio Version 1.1.456, and R version 3.5.1 (2018-07-02)

Download and install JDK 8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Check if the JAVA_HOME system variable exists or is set from R:

Sys.getenv("JAVA_HOME") # (In my case it was "")

Open a command prompt or Power Shell as an Administrator and enter the following command

rundll32.exe sysdm.cpl,EditEnvironmentVariables

Add a new environment variable for "JAVA_HOME" JAVA_HOME = C:\Program Files\Java\jdk1.8.0_181\jre

Restart RStudio

From there I was able to send emails using:

library(mailR) send.mail( ... ) # Here I was sending emails requiring authentication with a user.name and passwd

I also used debug = TRUE just to see everything was working.

advait1987 commented 5 years ago

I have tried with JAVA11, JAVA 8. But still get following error. Error in .jnew("org.apache.commons.mail.ImageHtmlEmail") : java.lang.NoClassDefFoundError: javax/activation/DataSource

FYI:

Sys.getenv("JAVA_HOME") [1] "/usr/lib/jvm/java-8-oracle"

emiliotorres commented 5 years ago

Same problem here. Unable to configure the rJava package. I had to send a lot of emails and I did a workaround: If you are using Linux, you can use mutt, a program to send emails (sudo apt install mutt).

Remember to change the config of muttrc in the following function:

password <- "xxx"
to <- c("m1@gmail.com","m2@gmail.com")
subject <- "test"
body.file <- "body.txt"
attach.files <- c("f1.png","f2.png")
CC <- c("a1@gmail.com","a2@gmail.com")
BCC <- NULL

send_email(password,to,subject,body.file,attach.files=attach.files,CC=CC)

send_email <- function(password,to,subject,body.file,attach.files=NULL,CC=NULL,BCC=NULL){
    ## sudo apt install mutt
    dotmuttrc <- tempfile("muttrc") ##"~/.muttrc"
    configdotmuttrc <- paste0(
        "set smtp_pass=\"",password,"\"\n",
        "set smtp_url='smtp://me@mycompany.com@smtp.office365.com:587/'
set hostname = mycompany.com
set ssl_force_tls = yes
set smtp_authenticators = 'login'
set from = 'me@mycompany.com'\n"
)
    cat(configdotmuttrc,file=dotmuttrc)
    command <- paste0("mutt -F ", dotmuttrc," -s '",subject,"' ")
    if(!is.null(CC)) command <- paste(command ,paste(paste0(" -c ", CC),collapse=" "))
    if(!is.null(BCC)) command <- paste(command ,paste(paste0(" -b ", BCC),collapse=" "))
    if(!is.null(attach.files)) command <- paste(command ,paste(paste0(" -a ", attach.files),collapse=" "), " -- ")
    command <- paste(command,paste(to,collapse= " "))
    command <- paste(command, " < ", body.file)
    system(command)
}
eni0tna commented 5 years ago

Hi @rpremraj any news on this topic? I have the same issue with R 3.5.0 / mailR / Java 11. Thanks!

wush978 commented 5 years ago

After putting following two jars into system.file("java", package = "mailR"), the issue is resolved on my computer:

sdas1983 commented 5 years ago

@wush978 , I have used your instruction , but still getting below 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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) 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.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.base/java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) at java.base/java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148) at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) at java.base/java.net.Socket.connect(Socket.java:591) at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:657) 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

justasmundeikis commented 5 years ago

Linux Mint 19.2 x86_64-pc-linux-gnu
Kernel: 4.15.0-58-generic R version: 3.6.1 (2019-07-05) RSstudio version: 1.2.1335

The same error here

 Error in .jnew("org.apache.commons.mail.ImageHtmlEmail") : 
 java.lang.NoClassDefFoundError: javax/activation/DataSource

If I run Sys.getenv("JAVA_HOME") ir returns "" after setting with Sys.setenv(JAVA_HOME="/usr/lib/jvm/default-java"); Sys.getenv("JAVA_HOME") returns "/usr/lib/jvm/default-java" But after restart of RStudio the command Sys.getenv("JAVA_HOME") returns again ""

Any ideas how to solve the issue under Linux?

filak commented 4 years ago

Thanks to @wush978 I was able to locate the missing jars.

Just download it and copy it to the ...\R-3.6.2\library\mailR\java\ folder.

Important - restart R after copying the jars.

The following JAVA versions seems to work:

Sys.setenv(JAVA_HOME="C:\java\AdoptOpenJDK\jdk-11.0.6.10-hotspot");

Sys.setenv(JAVA_HOME="C:\java\AmazonCorretto11\jdk11.0.7_10");

Sys.setenv(JAVA_HOME="C:\java\OpenJDK8\jdk8u252-b09");

Sys.setenv(JAVA_HOME="c:\java\Oracle\jre1.8.0_251");

Sys.getenv("JAVA_HOME")

cezarags commented 4 years ago

Depois de colocar os seguintes dois frascos system.file("java", package = "mailR"), o problema foi resolvido no meu computador:

Obrigado, Tbm adicionei ao projeto e funcionou!

absognety commented 3 years ago

After putting following two jars into system.file("java", package = "mailR"), the issue is resolved on my computer:

Thanks @wush978 , after doing this restarting R in R studio worked for me, but you have to install Java 8 and configure it to be default java using update-alternatives. Downloading these jars without user-agent is difficult, so enable a ssh link between this and your local, Download them into your local and secure copy them into remote R server where this issue persists.