我一直在用mailR软件包来从我的Gmail帐户发送邮件,但到目前为止我一直无法使它工作。其代码如下(与隐私/安全“AAAA”取代电子邮件和密码):R mailR包发送消息给STMP服务器(gmail)
library(mailR)
sender <- '[email protected]'
recipients <- c('[email protected]')
send.mail(from = sender,
to = recipients,
subject = 'My bot sent this',
body = 'Test Successful',
smtp = list(host.name = 'stmp.gmail.com', port= 587,
user.name = '[email protected]',
passwd = 'aaaa', tls= TRUE),
authenticate = TRUE,
send = TRUE)
从我的理解,这似乎是一个适当的设置为这个包。此外,我已确保双重登录已关闭,并且已启用“允许访问不太安全的应用程序”。我也用tls和ssl(完成适当的端口)尝试了这一点,这没有什么区别。
当我运行代码,我得到了以下错误:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : stmp.gmail.com:587
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: stmp.gmail.com, 587; timeout 60000;
nested exception is:
java.net.UnknownHostException: stmp.gmail.com
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.UnknownHostException: stmp.gmail.com
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 com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
... 13 more
NULL
Error: EmailException (Java): Sending the email to the following server failed : stmp.gmail.com:587
为了记录在案,这里是回溯输出,以及:
> traceback()
10: stop(list(message = "org.apache.commons.mail.EmailException: Sending the email to the following server failed : stmp.gmail.com:587",
call = .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), jobj = <S4 object of class "jobjRef">))
9: .Call(RJavaCheckExceptions, silent)
8: .jcheck(silent = FALSE)
7: .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)
6: .jrcall(x, name, ...)
5: email$send() at MessageBot.R#15
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("MessageBot.R")
任何想法是怎么回事?
我会给一个镜头,但我对如何使这项工作在mailR答案仍然打开! –