当我遇到java.lang错误时,如何使用gmail发送带有r的电子邮件

zzwlnbp8  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(356)

我一直在尝试用gmail地址从r发送电子邮件,但我总是得到相同的错误代码。有没有办法纠正这个错误。我知道以前也有人问过类似的问题,但用这些答案我想不出来。谢谢你的帮助
而且,我的google账户的参数已经调整过了。
以下是我发送电子邮件的代码:

library(mailR)
sender <- "abc@gmail.com"
recipients <- c("abc@gmail.com")
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 = "abc@gmail.com",            
                      passwd = "123abc", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

这是错误代码

java.lang.NoClassDefFoundError: javax/activation/DataHandler
    at org.apache.commons.mail.Email.createMimeMessage(Email.java:1832)
    at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1268)
    at org.apache.commons.mail.Email.send(Email.java:1436)
    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: java.lang.ClassNotFoundException
    at RJavaClassLoader.findClass(RJavaClassLoader.java:383)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 8 more
NULL
NoClassDefFoundError (Java): javax/activation/DataHandler[1] "Java-Object{org.apache.commons.mail.SimpleEmail@1ed6993a}"
>
7lrncoxx

7lrncoxx1#

自Java9发布以来 javax.activation 已删除。因此,如果您需要使用Java9或更高版本,只需安装这些JAR
https://mvnrepository.com/artifact/javax.activation/javax.activation-api/1.2.0
https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0 并投入 system.file("java", package = "mailR") 文件夹。

相关问题