gpt4 book ai didi

java - mailR 连接被 Linux 拒绝,但 Windows 不拒绝

转载 作者:太空宇宙 更新时间:2023-11-04 03:49:35 24 4
gpt4 key购买 nike

我有mailR(发送电子邮件的R语言包)尝试从我的gmail帐户发送一些电子邮件。它在 Windows 上完美运行,但在 Linux 上我收到以下错误。在下面的示例中,我替换了电子邮件、用户名和密码。

代码:

library(mailR)
emails <- c("example1@host.com")

send.emails <- function() {
for(x in emails){
send.mail(from = from1,
to = x,
subject = subject1,
body = body1,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = username,
passwd = password, ssl = TRUE),
authenticate = TRUE,
send = TRUE)
}
}

send.emails()

错误:

> send.emails()
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(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.NULL
java:606)
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 refused
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656)
at javax.mail.Service.connect(Service.java:367)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:175)
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 refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:299)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:208)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)
... 13 more
Show Traceback

Rerun with Debug
Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465

同样,我在 Windows 上完全没有收到任何错误,并且电子邮件通过,当我在 Linux 上运行相同的脚本时,我收到所有这些错误。连接被拒绝...

如果我可以从我的 Linux 机器上运行这个脚本那就太好了。谢谢!

最佳答案

好的,我有答案了。令人惊讶的是,R 在 Windows 上运行不是问题,而在 Linux 上则不然(例如 download.file --internet2 或许多其他示例)。

Peerguardian 正在 Linux 系统上运行,并且 smtp.gmail.com 不知何故位于黑名单中。

我已将 smtp.gmail.com 列入白名单,现在一切正常!

我能够通过 IP 或白名单端口 465 列入白名单,两者都有效。

关于java - mailR 连接被 Linux 拒绝,但 Windows 不拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26825328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com