Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a mail from R using mailR package getting the error

Tags:

r

sendmailr

I am trying to sending a mail from R using mailR package but getting the error.

My code :

subject <- "Montly Report"
today<-Sys.Date()
fileName <- sprintf('./DailyReports/LaunchDaily_%s.html', format(today, format = "%d-%m-%y"))
body <- "Testing Document"

send.mail(from = from,
          to = to,
          cc = cc,
          bcc = bcc,
          subject = subject,
          attach.files = fileName,
          html = T,
          inline = T,
          body = body,
          smtp = list(host.name = "smtp.gmail.com", port = 465, 
                      user.name = "email id",            
                      passwd = "password", ssl = TRUE),
          authenticate = T,
          send = T
)

and error :

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

i have tried to search in google and github also but not getting the fix to the prob.

Note: : Link i have gone through the Link and tried also the code but not worked for me.

System OS : Ubuntu 18.04, R Studio : 1.1.456

like image 834
sai saran Avatar asked Nov 06 '25 01:11

sai saran


2 Answers

Problem is raised due to the mismatch of Java version error.

For Ubuntu users need to install Oracle Java instead of JDK version and need to set home path properly.

Then google account setting need to be surely lessappsecure to 'turn ON'.

to set java..type in Terminal

sudo add-apt-repository ppa:webupd8team/java
sudo apt update; sudo apt install oracle-java8-installer
javac -version

OUTPUT

java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

and test once in R like java path is correctly working or not with rJava

try to run below libraries

library(rJava)
library(mailR) 

if both libraries will run without any errors then JAVA is correctly working.

Successful Message :

After completion of sending the mail in r session you will get the message like below :

[1] "Java-Object{org.apache.commons.mail.ImageHtmlEmail@32709393}"

NOTE:

Try to careful while installing and setting the path properly in Ubuntu itself.

like image 114
sai saran Avatar answered Nov 09 '25 02:11

sai saran


Basically, you want to avoid that kind of dependency bug. I suggest dropping tha package mailR in favor of emayili which do not cause that kind of problems.

emayili GitHub page

like image 20
Mesozoik Avatar answered Nov 09 '25 01:11

Mesozoik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!